Dans mon Webservice, j'ai un modèle:Comment faire pour répondre à tous les champs de champ avec omitempty tag dans Golang?
// Comment struct
type Comment struct {
Owner UserObject `json:"owner"`
ID int64 `json:"id"`
Message string `json:"message"`
Mentions []MentionObject `json:"mentions,omitempty"`
CreatedAt int64 `json:"created_at,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
Status int `json:"status,omitempty"`
CanEdit bool `json:"can_edit"`
CanDelete bool `json:"can_delete"`
}
// UserObject struct
type UserObject struct {
ID int64 `json:"id"`
Username string `json:"username"`
FullName string `json:"full_name"`
Avatar string `json:"avatar"`
}
// MentionObject struct
type MentionObject struct {
ID int64 `json:"id"`
Length int64 `json:"length"`
Offset int64 `json:"offset"`
}
je utiliser le gin gonic pour le routage
routes.GET("/user", func(c *gin.Context) {
c.JSON(200, Comment{})
})
Je dois retourner tous les champs de cette structure, je sais que ça va répondre JSON :
{
"owner": {
"id": 0,
"username": "",
"full_name": "",
"avatar": ""
},
"id": 0,
"message": "",
"can_report": false,
"can_edit": false,
"can_delete": false
}
Je sais que c'est vrai, mais je veux toujours la réponse tout champ. Comment faire cela?