add result limiting in blog posts

This commit is contained in:
Morgan Bazalgette 2017-01-28 15:41:12 +01:00
parent ab89bda819
commit 0d58fd3f63

View File

@ -103,7 +103,7 @@ func BlogPostsGET(md common.MethodData) common.CodeMessager {
// create response and return
var r blogPostsResponse
r.Code = 200
r.Posts = posts
r.Posts = blogLimit(posts, md.Query("l"))
return r
}
@ -173,6 +173,14 @@ func BlogPostsGET(md common.MethodData) common.CodeMessager {
var r blogPostsResponse
r.Code = 200
r.Posts = posts
r.Posts = blogLimit(posts, md.Query("l"))
return r
}
func blogLimit(posts []blogPost, s string) []blogPost {
i := common.Int(s)
if i >= len(posts) || i < 1 {
return posts
}
return posts[:i]
}