我正在尝试使用带有mongo的beego。 你可以找到我的来源: https://github.com/wsourabh/bapi
但是在打电话的时候 V1 /账户/:ID我总是得到回复
curl -v localhost:8080/v1/accounts/0df542560fbfc39a4bdb24d0ca44d37e
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /v1/accounts/0df542560fbfc39a4bdb24d0ca44d37e HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Length: 46
< Content-Type: application/json; charset=utf-8
< Server: beegoServer:1.6.1
< Date: Tue, 17 May 2016 18:53:50 GMT
<
{
"Id": "0df542560fbfc39a4bdb24d0ca44d37e"
* Connection #0 to host localhost left intact
}
其他字段空白。有人可以指导我如何正确地做到这一点。
我希望输出类似
的内容{
"_id":"account_id",
"created":"created_date",
"updated":"updated_date",
"email": "wsourabh@aaa.com"
"wcd_guid" : "some_id"
"name":
{
"full" :"sourabh J",
"last" : "J",
"first" :"sourabh"
}
"country": "IN",
"status": "new"
}
在为mgo启用调试时,我将调试日志作为:
MGO: session.go:3062: Query 0xc820378900 document unmarshaled: &models.Accounts{Id:"0df542560fbfc39a4bdb24d0ca44d37e", created:"", updated:"", email:"", wcd_guid:"", name:(*models.Name)(nil), country:"", status:""}
答案 0 :(得分:0)
阅读beego的文档和示例。为了服务json,您必须向模型添加{{1}}标记。
如果这不能解决您的问题,则意味着beego会自动从您的结构中删除零值进行编组。在这种情况下,您更有可能从beego的开发人员而不是StackOverflow寻求帮助。