-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathjson2go.go
81 lines (74 loc) · 1.62 KB
/
json2go.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
const (
// OutTypeForPrint
OutTypeForPrint = "print"
// OutTypeForFile
OutTypeForFile = "file"
)
const (
// DefaultJsonFile 默认json文件
DefaultJsonFile = "json2go.json"
// DefaultOutType 默认输出方式
DefaultOutType = "print"
// DefaultOutFile 默认输出文件
DefaultOutFile = "gen_json2go_types.go"
// DefaultStructName 结构体名称
DefaultStructName = "Json2GoAutoGenerate"
)
const (
Xmap = "map[string]interface {}"
Xlist = "[]interface {}"
Xstring = "string"
goBegin = "package json2go\n\n"
)
var (
Xstr = "%s"
Xbegin = "\ntype %s struct {"
Xend = "}\n"
Xkeyv = "%s %s %s"
Xkeyvori = "%s %s %s"
Xkeyvtag = "%s %s `json:\"%s\"`"
)
type xjson struct {
Name string
Msg string
LowerCase bool
UpperCase bool
JSONTag bool
MapTag map[string]string
Parent map[string]interface{}
Sub []map[int]string
Out []string
// json文件,默认json2go.json
JsonFile string
// 输出类型[print file],默认print
OutType string
// 输出文件,默认json2go_types.go
OutFile string
}
// New returns a new xjson
func New(msg, jsonFile, outType, outFile string) *xjson {
return &xjson{
Name: DefaultStructName,
Msg: msg,
JSONTag: true,
MapTag: map[string]string{},
JsonFile: jsonFile,
OutType: outType,
OutFile: outFile,
}
}
// reloade
func (xj *xjson) Flush() {
*xj = *&xjson{
Name: xj.Name,
Msg: xj.Msg,
MapTag: map[string]string{},
Parent: map[string]interface{}{},
Sub: []map[int]string{},
Out: []string{},
JSONTag: true,
LowerCase: false,
UpperCase: false,
}
}