mapstructure:",squash"这个标签怎么用啊
看介绍是把对应的struct直接提到本级来,比如:
type ShoppingCart struct {
BaseModel `mapstructure:",squash"`
User int32 `gorm:"type:int;index"`
Goods int32 `gorm:"type:int;index"`
Nums int32 `gorm:"type:int"`
Checked bool
}
type BaseModel struct {
ID int32 `gorm:"primarykey;type:bigint"`
CreatedAt time.Time `gorm:"column:add_time"`
UpdatedAt time.Time `gorm:"column:upd_time"`
DeletedAt gorm.DeletedAt
IsDeleted bool
}
在使用的时候就可以ShoppingCart{ID:1} 这样用了,我看别人框架里这么用的没有问题,但是我自己这么写就无法直接使用ID等字段,用了就报错,是不是还有哪些细节需要处理?
推荐文章: