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?
You should be able to wrap your data structure into a custom type which hides the app field:
type ExportAppVersion struct {
AppVersion
App `json:"-"`
}
This should hide the App
field from being exposed.
type AppVersion struct {
Id int64 `json:"id"`
App App `json:"-"`
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"`
}
More info - json-go