🌐 AI搜索 & 代理 主页
blob: 8859341c1f9bc3d21bc54186b5f6c4ce0adfa4e6 [file] [log] [blame]
Fatih Arslanf3d38022014-08-13 19:53:151package structs
Fatih Arslanfc5199c2014-08-07 15:17:412
3import "strings"
4
5// tagOptions contains a slice of tag options
6type tagOptions []string
7
Fatih Arslan1b32eb12014-08-08 08:49:068// Has returns true if the given optiton is available in tagOptions
Fatih Arslanfc5199c2014-08-07 15:17:419func (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
Fatih Arslan137635f2014-08-07 18:23:0120// which comes after a name. A tag is in the form of: "name,option1,option2".
21// The name can be neglectected.
Fatih Arslanfc5199c2014-08-07 15:17:4122func parseTag(tag string) (string, tagOptions) {
Fatih Arslanfc5199c2014-08-07 15:17:4123 // tag is one of followings:
Fatih Arslanf59cd822014-08-08 10:45:0424 // ""
25 // "name"
Fatih Arslanfc5199c2014-08-07 15:17:4126 // "name,opt"
27 // "name,opt,opt2"
28 // ",opt"
Fatih Arslanf59cd822014-08-08 10:45:0429
30 res := strings.Split(tag, ",")
Fatih Arslanfc5199c2014-08-07 15:17:4131 return res[0], res[1:]
32}