-1

I was trying few exapmles using beego with mongo. you can find my source at : https://github.com/wsourabh/bapi

but while calling the v1/accounts/:id

I am always getting the response as

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
}

other fields are coming as blank. can someone guide me how to do it correctly.

I want to have output something like

{
"_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"
}

while enabling the debug for mgo , I am getting the debug log as :

MGO: session.go:3062: Query 0xc820378900 document unmarshaled: &models.Accounts{Id:"0df542560fbfc39a4bdb24d0ca44d37e", created:"", updated:"", email:"", wcd_guid:"", name:(*models.Name)(nil), country:"", status:""}
Sourabh Jain
  • 55
  • 1
  • 4
  • 1
    Please put the relevant code in the question itself. You can't expect others go through your entire project's code. – Aruna Herath May 17 '16 at 19:24
  • 1
    This is not very nice to let the viewers go through your github project in order to solve your issue, you should provide a minimal example of the code you think is incriminated. – T. Claverie May 18 '16 at 02:11

1 Answers1

0

Read beego's documentation and examples. In order to serve json, you have to add json tags to your model.

If this does not solve your problem, it means beego automatically removes zero value from your structure from being marshalled. In this case, you are more likely to find help from beego's developer rather than from StackOverflow.

T. Claverie
  • 11,380
  • 1
  • 17
  • 28