我有这样的模型:
type Service struct {
Id uint64
Name string
Secret string
Disabled bool
}
并且想要使用诸如 form
、valid
和 orm
之类的注释。我找不到应该如何声明这些注释。应该是一个还是多个?如果很多,我应该使用什么分隔符?
最佳答案
引用自reflect.StructTag
:
By convention, tag strings are a concatenation of optionally space-separated key:"value" pairs.
因此您可以指定多个键值对,并用空格分隔,例如:
type Service struct {
Id uint64 `form:"id" valid:"Range(1, 999)" orm:"auto"`
}
在此答案中查看有关标签的更多信息:What are the use(s) for tags in Go?
关于go - beego中可以使用多个注解吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43498452/