我的代码中有这个结构。
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"`
}
我正在构建一个Web服务,不需要在JSON中发送
App
字段。我尝试了一些操作以从JSON中删除该字段,但我无法做到这一点。
我该如何实现?
有什么办法可以将struct设置为空吗?
我将GORM用作数据库访问层,所以不确定是否可以执行
App *App
,您知道它是否可以工作吗? 最佳答案
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"`
}
更多信息-json-go