-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtag.go
More file actions
49 lines (41 loc) · 865 Bytes
/
Copy pathtag.go
File metadata and controls
49 lines (41 loc) · 865 Bytes
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
package libconfig
import (
"reflect"
"strings"
)
type tagData struct {
Tagged bool
Name string
Optional bool
Base64 bool
JSON bool
}
func parseTag(f reflect.StructField, tag string) (tagData, error) {
result := tagData{}
// Get the tags
var tags string
tags, result.Tagged = f.Tag.Lookup(tag)
if !result.Tagged {
return result, nil
}
// Split into tokens and then parse the tokens
tagTokens := strings.Split(tags, ",")
// Parse: Name
result.Name = tagTokens[0]
if len(result.Name) == 0 {
return result, NewErrMissingNameTag(tags)
}
for i := 1; i < len(tagTokens); i++ {
switch tagTokens[i] {
case "base64":
result.Base64 = true
case "json":
result.JSON = true
case "optional":
result.Optional = true
default:
return tagData{}, NewErrInvalidTagOption(tags, tagTokens[i])
}
}
return result, nil
}