以下是我的代码

type AbstractAccount struct {
    Email        string `gorm:"unique;type:varchar"`
    PasswordHash string `gorm:"unique;type:varchar"`
}

type Planner struct {
    AbstractAccount
}

例如,我想将自定义验证器标记添加到EmailPlanner

type Planner struct {
    AbstractAccount `validator:"Email:customTag"`
}

有没有办法在验证器中使用它,或者有没有库可以这样做?

推荐答案

Sample program
inside that sample program there is a function called getFieldsWithCustomTag it takes a reflect value as an argument and recursively searches for fields with the tag c-tag:true(you can change this). It appends these fields to a slice and, if a nested struct is encountered, recursively calls itself to search for fields in the nested struct.

Go相关问答推荐

如何复制*C.char?

GO框架Echo中间件的使用

Redis:尽管数据存在,但 rdb.Pipelined 中出现redis:nil错误

该文件位于模块.内,该模块不包含在您的工作区中

Kperf 构建失败

无法使用带有 422 的 go-github 创建提交 - 更新不是快进

Go Template if 条件

致命错误 - 所有 Goroutines 都睡着了!僵局

在嵌套模板中使用变量,它也被定义为 go 模板中的变量?

Golang:如何判断通过缓冲通道进行通信时生产者或消费者是否较慢?

使用 golang 生成 vim

致命错误:找不到由 zergon321/reisen 引起的libavcodec/avcodec.h文件

如何根据 Go 中第二次出现的分隔符拆分字符串?

如何在没有内存分配的情况下压缩和发布文件

如何在 GORM 中获取字段值

Golang - 无法从 pipped Windows 命令中获取结果

退格字符在围棋操场中不起作用

如何断言类型是指向golang中接口的指针

是否存在一个Go泛型类型约束,该约束捕获了将类型用作映射中的键的能力?

Go http标准库中的内存泄漏?