英文:
Is it possible to use multiple annotations in beego?
问题
我有一个类似的模型:
type Service struct {
Id uint64
Name string
Secret string
Disabled bool
}
我想使用form
、valid
和orm
这样的注解。但是我找不到应该如何声明这些注解。是应该只有一个注解还是多个注解?如果是多个注解,应该使用什么分隔符?
英文:
I have model like:
type Service struct {
Id uint64
Name string
Secret string
Disabled bool
}
And want to use annotations like form
, valid
and orm
. And I can't find how I should declare these annotations. Should it be one or many? If many, what separator should I use?
答案1
得分: 2
> 按照惯例,标签字符串是一个可选的以空格分隔的键值对的串联。
因此,您可以通过空格分隔来指定多个键值对,例如:
type Service struct {
Id uint64 `form:"id" valid:"Range(1, 999)" orm:"auto"`
}
在这个答案中可以了解更多关于标签的内容:https://stackoverflow.com/questions/10858787/what-are-the-uses-for-tags-in-go/30889373#30889373
英文:
Quoting from reflect.StructTag
:
> By convention, tag strings are a concatenation of optionally space-separated key:"value" pairs.
So you may specify multiple key-value pairs separated by space, like:
type Service struct {
Id uint64 `form:"id" valid:"Range(1, 999)" orm:"auto"`
}
See more about tags in this answer: https://stackoverflow.com/questions/10858787/what-are-the-uses-for-tags-in-go/30889373#30889373
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论