-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.go
47 lines (43 loc) · 829 Bytes
/
tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package loader
import (
"strings"
)
//Tag struct field tag struct
type Tag struct {
//Name parsed name tag
Name string
//Flags field flags
Flags map[string]string
//Ignored field ignored flag
Ignored bool
}
//NewTag create new tag struct
func NewTag() *Tag {
return &Tag{
Flags: map[string]string{},
}
}
//ParseTag default parse tag func
//Parse field tag with given config
//Return parsed tag and any error if rasised.
func ParseTag(c *Config, value string) (*Tag, error) {
t := NewTag()
value = strings.TrimSpace(value)
if value == "" {
return t, nil
}
if value == "-" {
t.Ignored = true
return t, nil
}
v := strings.Split(value, ",")
t.Name = strings.TrimSpace(v[0])
l := len(v)
for i := 1; i < l; i++ {
k := strings.TrimSpace(v[i])
if k != "" {
t.Flags[k] = "1"
}
}
return t, nil
}