-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
encodeflag.go
61 lines (52 loc) · 985 Bytes
/
encodeflag.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package dynamo
import "reflect"
type encodeFlags uint
const (
flagSet encodeFlags = 1 << iota
flagOmitEmpty
flagOmitEmptyElem
flagAllowEmpty
flagAllowEmptyElem
flagNull
flagUnixTime
flagNone encodeFlags = 0
)
func fieldInfo(field reflect.StructField) (name string, flags encodeFlags) {
tag := field.Tag.Get("dynamo")
if tag == "" {
return field.Name, flagNone
}
begin := 0
for i := 0; i <= len(tag); i++ {
if !(i == len(tag) || tag[i] == ',') {
continue
}
part := tag[begin:i]
begin = i + 1
if name == "" {
if part == "" {
name = field.Name
} else {
name = part
}
continue
}
switch part {
case "set":
flags |= flagSet
case "omitempty":
flags |= flagOmitEmpty
case "omitemptyelem":
flags |= flagOmitEmptyElem
case "allowempty":
flags |= flagAllowEmpty
case "allowemptyelem":
flags |= flagAllowEmptyElem
case "null":
flags |= flagNull
case "unixtime":
flags |= flagUnixTime
}
}
return
}