我是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}, ... ]}
1 回答
qq_遁去的一_1
TA贡献1725条经验 获得超7个赞
您可能需要更改
playList gorest.EndPoint方法:“ GET”路径:“ / list /”输出:“ [] Item”`
到 playList gorest.EndPoint方法:“ GET”路径:“ / list /”输出:“ ItemStore”`
和
var(
itemStore []Item
)
至
type ItemStore struct {
Items []Item
}
var(
itemStore ItemStore
)
完整的工作程序将更容易调试。
- 1 回答
- 0 关注
- 177 浏览
添加回答
举报
0/150
提交
取消