示例#1
0
文件: api.go 项目: supermouseno1/b
// Show returns a single post.
func (ap ApiPosts) Show(params martini.Params, r render.Render) {
	var post models.Post

	root := util.Config().App.PostsDir
	path := models.ParsePostId(params["id"])
	file := root + string(os.PathSeparator) + path
	found := false

	for _, p := range models.GetAllPosts(root) {
		if p.Directory+string(os.PathSeparator)+p.Filename == file {
			post = p
			found = true
		}
	}

	if found {
		r.JSON(200, post)
	} else {
		r.Error(404)
	}
}
示例#2
0
文件: api.go 项目: supermouseno1/b
// Index returns all available posts.
func (ap ApiPosts) Index(r render.Render) {
	root := util.Config().App.PostsDir
	posts := models.GetAllPosts(root)

	r.JSON(200, posts)
}