-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructtag.go
More file actions
58 lines (50 loc) · 2.16 KB
/
structtag.go
File metadata and controls
58 lines (50 loc) · 2.16 KB
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
package structtags
import (
"github.com/fatih/structtag"
"github.com/ldez/structtags/variant/fatih"
mapsmultikeys "github.com/ldez/structtags/variant/maps/multikeys"
mapsraw "github.com/ldez/structtags/variant/maps/raw"
mapsvalues "github.com/ldez/structtags/variant/maps/values"
sliceraw "github.com/ldez/structtags/variant/slices/raw"
slicevalues "github.com/ldez/structtags/variant/slices/values"
"github.com/ldez/structtags/variant/structured"
)
// ParseToMap parses a struct tag to a `map[string]string`.
// Ignore duplicated keys by default.
func ParseToMap(tag string, options ...mapsraw.Option) (mapsraw.Tag, error) {
return mapsraw.Parse(tag, options...)
}
// ParseToMapMultikeys parses a struct tag to a `map[string][]string`.
// For non-conventional tags where the key is repeated.
func ParseToMapMultikeys(tag string) (mapsmultikeys.Tag, error) {
return mapsmultikeys.Parse(tag)
}
// ParseToMapValues parses a struct tag to a `map[string][]string`.
// The value is split on comma.
// Ignore duplicated keys by default.
func ParseToMapValues(tag string, options ...mapsvalues.Option) (mapsvalues.Tag, error) {
return mapsvalues.Parse(tag, options...)
}
// ParseToSlice parses a struct tag to a slice of [sliceraw.Tag].
// Ignore duplicated keys by default.
func ParseToSlice(tag string, options ...sliceraw.Option) (sliceraw.Tags, error) {
return sliceraw.Parse(tag, options...)
}
// ParseToSliceValues parses a struct tag to a slice of [slicevalues.Tag].
// The value is split on comma.
// Ignore duplicated keys by default.
func ParseToSliceValues(tag string, options ...slicevalues.Option) (slicevalues.Tags, error) {
return slicevalues.Parse(tag, options...)
}
// ParseToStructured parses a struct tag to a [structured.Tag].
// Allows modifying the struct tags.
// The value is split on comma.
// Ignore duplicated keys by default.
func ParseToStructured(tag string, options ...structured.Option) (*structured.Tag, error) {
return structured.Parse(tag, options...)
}
// ParseToFatih parses a struct tag to a [*structtag.Tags].
// The value is split on comma.
func ParseToFatih(tag string, escapeComma bool) (*structtag.Tags, error) {
return fatih.Parse(tag, escapeComma)
}