2

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?

icza
  • 389,944
  • 63
  • 907
  • 827
Oleksandr Savchenko
  • 642
  • 3
  • 10
  • 35

1 Answers1

2

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: What are the use(s) for tags in Go?

Community
  • 1
  • 1
icza
  • 389,944
  • 63
  • 907
  • 827
  • tank you! should I set `orm:"id"` or it's ok to miss it ad it will be with some kind of autogenerating? – Oleksandr Savchenko Apr 19 '17 at 14:33
  • 1
    @OleksandrSavchenko You can leave it out, it was just an example. Read more about it here: [Models – Beego ORM](https://beego.me/docs/mvc/model/overview.md). – icza Apr 19 '17 at 14:56