blob: 136a31eba9a9757d18097e7f82961a1b731ad27d [file] [log] [blame]
Matteo Scandolof65e6872020-04-15 15:18:43 -07001package structs
2
3import "strings"
4
5// tagOptions contains a slice of tag options
6type tagOptions []string
7
8// Has returns true if the given option is available in tagOptions
9func (t tagOptions) Has(opt string) bool {
10 for _, tagOpt := range t {
11 if tagOpt == opt {
12 return true
13 }
14 }
15
16 return false
17}
18
19// parseTag splits a struct field's tag into its name and a list of options
20// which comes after a name. A tag is in the form of: "name,option1,option2".
21// The name can be neglectected.
22func parseTag(tag string) (string, tagOptions) {
23 // tag is one of followings:
24 // ""
25 // "name"
26 // "name,opt"
27 // "name,opt,opt2"
28 // ",opt"
29
30 res := strings.Split(tag, ",")
31 return res[0], res[1:]
32}