有没有办法为结构内的每个结构执行 BeforeCreate 和 BeforeUpdate 挂钩?

有没有办法为结构内的每个结构执行 beforecreate 和 beforeupdate 挂钩?

问题内容

我有以下代码:

type innerstructa struct { a string } type innerstructb struct { b string } func (a *a) beforecreate(scope *gorm.scope) error { return scope.setcolumn("a", uuid.new().string()) } func (b *b) beforecreate(scope *gorm.scope) error { return scope.setcolumn("b", uuid.new().string()) } type outerstruct struct { innerstructa innerstructb id string `gorm:"type:varchar(40);not null"` }登录后复制