我是Go和GoRest的新手,但对此有疑问。
如何在gorest EndPoint语法中为输出数据提供JSON对象ID,如下所述?
我有一个简单的例子:
type HelloService struct {
gorest.RestService `root:"/api" consumes:"application/json" produces:"application/json"`
playList gorest.EndPoint `method:"GET" path:"/list/" output:"[]Item"`
playItem gorest.EndPoint `method:"PUT" path:"/go/{Id:int}" postdata:"Item"`
}
func(serv HelloService) PlayList() []Item{
serv.ResponseBuilder().SetResponseCode(200)
return itemStore
}
type Item struct{
Id int
FileName string
Active bool
}
var(
itemStore []Item
)
生成的JSON是:
[{"Id":1,"FileName":"test :1","Active":false},{"Id":2,"FileName":"test :2","Active":false}, ... ]
但是,Mustache.js无法解析它,因为它首先需要对象ID。小胡子想要这样的东西:
{
"repo": [{"Id":1,"FileName":"test :1","Active":false},{"Id":2,"FileName":"test
:2","Active":false}, ... ]
}
qq_遁去的一_1
相关分类