forked from jszwec/csvutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag.go
47 lines (42 loc) · 733 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 csvutil
import (
"reflect"
"strings"
)
type tag struct {
name string
prefix string
empty bool
omitEmpty bool
ignore bool
inline bool
}
func parseTag(tagname string, field reflect.StructField) (t tag) {
tags := strings.Split(field.Tag.Get(tagname), ",")
if len(tags) == 1 && tags[0] == "" {
t.name = field.Name
t.empty = true
return
}
switch tags[0] {
case "-":
t.ignore = true
return
case "":
t.name = field.Name
default:
t.name = tags[0]
}
for _, tagOpt := range tags[1:] {
switch tagOpt {
case "omitempty":
t.omitEmpty = true
case "inline":
if walkType(field.Type).Kind() == reflect.Struct {
t.inline = true
t.prefix = tags[0]
}
}
}
return
}