concept all post in category go

appears as: ll posts
Go Web Programming

This is an excerpt from Manning's book Go Web Programming.

6.3.7. Getting all posts

One common function is to get all posts from the database, with a given limit. In other words, you want to do the following:

Listing 6.12. Getting all posts
func Posts(limit int) (posts []Post, err error) { rows, err := Db.Query("select id, content, author from posts limit $1", limit) if err != nil { return } for rows.Next() { post := Post{} err = rows.Scan(&post.Id, &post.Content, &post.Author) if err != nil { return } posts = append(posts, post) } rows.Close() return }