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}, ... ]
しかし、オブジェクト ID が先に必要なため、Mustache.js はそれを解析できません。口ひげは次のようなものを望んでいます:
{
"repo": [{"Id":1,"FileName":"test :1","Active":false},{"Id":2,"FileName":"test
:2","Active":false}, ... ]
}