我正在尝试编写 Gorm 自定义数据类型:https : //gorm.io/docs/data_types.html
type MyDataType struct {}
func (f *MyDataType) Scan(value interface{}) error {
//
}
func (f MyDataType) Value() (driver.Value, error) {
//
}
Run Code Online (Sandbox Code Playgroud)
由于某些原因,我需要访问上下文Scan或能够检索字段标签。
有没有办法做到这一点 ?谢谢
小智 2
值基于用户空间,您可能需要将代码更改为如下所示:
type MyDataType struct {}
func (f *MyDataType) Scan(context context.Context, value interface{}) error {
// proceed the context right there
}
func (f MyDataType) Value() (driver.Value, error) {
//
}
Run Code Online (Sandbox Code Playgroud)