douxie1692
2016-08-02 10:35陶醉于mgo.v2-如何将集合中的所有数据作为json返回?
I'm trying to build an API endpoint using Revel for Go.
My models/models.go looks like this -
type Category struct {
Name string `bson:"name"`
Slug string `bson:"slug"`}
func GetCategories(s *mgo.Session) *Category {
var results []Category
Collection(s).Find(nil).All(&results)
return results}
My controllers/book.go looks like this -
type Category struct {
*revel.Controller
revelbasic.MongoController}
func (c Category) Categories() revel.Result {
b := models.GetCategories(c.MongoSession)
return c.RenderJson(b)}
I've configured my conf/routes like this -
GET /categories Book.Categories
When I run the code, I get this error -
cannot use results (type []Category) as type *Category in return argument
I understand that I'm doing something wrong with the database query. Please help!
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 陶醉于mgo.v2-如何将集合中的所有数据作为json返回?
- revel
- 1个回答