Example #1
0
func servePosts(w http.ResponseWriter, r *http.Request) error {
	var opt thesrc.PostListOptions
	if err := schemaDecoder.Decode(&opt, r.URL.Query()); err != nil {
		return err
	}

	opt.CodeOnly = true

	if opt.PerPage == 0 {
		opt.PerPage = 60
	}

	posts, err := APIClient.Posts.List(&opt)
	if err != nil {
		return err
	}

	return renderTemplate(w, r, "posts/list.html", http.StatusOK, struct {
		Posts []*thesrc.Post
	}{
		Posts: posts,
	})
}