Merge pull request #21 from javierprovecho/master

Fix JSON Struct example
This commit is contained in:
Manu Mtz.-Almeida 2014-07-02 11:54:39 +02:00
commit 3bfbf986a2
1 changed files with 7 additions and 3 deletions

View File

@ -190,12 +190,16 @@ func main() {
r.GET("/moreJSON", func(c *gin.Context) { r.GET("/moreJSON", func(c *gin.Context) {
// You also can use a struct // You also can use a struct
var msg struct { var msg struct {
Name string `json:"user"`
Message string Message string
Status int Number int
} }
msg.Name = "Lena"
msg.Message = "hey" msg.Message = "hey"
msg.Status = 200 msg.Number = 123
c.JSON(200, msg.Status) // Note that msg.Name becomes "user" in the JSON
// Will output : {"user": "Lena", "Message": "hey", "Number": 123}
c.JSON(200, msg)
}) })
r.GET("/someXML", func(c *gin.Context) { r.GET("/someXML", func(c *gin.Context) {