-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.go
39 lines (34 loc) · 1.19 KB
/
dump.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
package venom
import "github.com/fsamin/go-dump"
// Dump dumps v as a map[string]interface{}.
func Dump(v interface{}) (map[string]interface{}, error) {
e := dump.NewDefaultEncoder()
e.ExtraFields.Len = true
e.ExtraFields.Type = true
e.ExtraFields.DetailedStruct = true
e.ExtraFields.DetailedMap = true
e.ExtraFields.DetailedArray = true
e.Formatters = []dump.KeyFormatterFunc{dump.WithDefaultLowerCaseFormatter()}
return e.ToMap(v)
}
// DumpString dumps v as a map[string]string{}, key in lowercase
func DumpString(v interface{}) (map[string]string, error) {
e := dump.NewDefaultEncoder()
e.ExtraFields.Len = true
e.ExtraFields.Type = true
e.ExtraFields.DetailedStruct = true
e.ExtraFields.DetailedMap = true
e.ExtraFields.DetailedArray = true
e.Formatters = []dump.KeyFormatterFunc{dump.WithDefaultLowerCaseFormatter()}
return e.ToStringMap(v)
}
// DumpStringPreserveCase dumps v as a map[string]string{}
func DumpStringPreserveCase(v interface{}) (map[string]string, error) {
e := dump.NewDefaultEncoder()
e.ExtraFields.Len = true
e.ExtraFields.Type = true
e.ExtraFields.DetailedStruct = true
e.ExtraFields.DetailedMap = true
e.ExtraFields.DetailedArray = true
return e.ToStringMap(v)
}