I've this struct in my code.
type AppVersion struct {
Id int64 `json:"id"`
App App `json:"app,omitempty" out:"false"`
AppId int64 `sql:"not null" json:"app_id"`
Version string `sql:"not null" json:"version"`
Sessions []Session `json:"-"`
SessionsCount int `sql:"-"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt time.Time `json:"deleted_at"`
}
I'm building a webservice and I don't need to send the App field in the JSON.
I've tried a few things to remove the field from the JSON but I haven't been able to do it.
How can I achieve this? Is there any way to set struct as empty?
I'm using GORM as database access layer, so I'm not sure if I can do App *App, do you know if it will work?
json.Marshalerandjson.UnmarshaleronAppVersionif you want to further control serialization outside of the spec of thejsonpackage.MarshalJSONandUnmarshalJSONonAppVersion. Thejsonpackage will call those methods if they exists instead of using its own reflection based marshaling.