-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
124 lines (105 loc) · 3.35 KB
/
config.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package quickstart
import "github.com/ACking-you/quickstart_project/common_info"
type Config struct {
//数据库连接
username string
password string
host string
database string
port int
ormPackageName string //gorm包名
sqlPackageName string //sql包名
ginPackageName string //gin包名
basePath string //用于生成文件的基本路径,需要为文件夹
table string //如果指定了表,则只针对该表生成
realTableNameMethod string //若该字段被赋值,则以该字段名生成获取真实表明的方法
tagKey string // tag字段的key值,默认是gorm
enableGoTidy bool //是否自动go get
enableJsonTag bool // 是否添加json的tag, 默认不添加
enableDebug bool //是否打印结构体的解析结果
tableFilterHook func(tableName string) bool //用于过滤不需要生成的表结构
}
func DefaultConfig(projectName, username, password, host string, port int, database string) *Config {
common_info.ProjectPackageName = projectName
return &Config{
username: username,
password: password,
host: host,
port: port,
ormPackageName: "gorm.io/gorm",
sqlPackageName: "gorm.io/driver/mysql",
ginPackageName: "github.com/gin-gonic/gin",
database: database,
basePath: "./", //默认为当前项目根目录
realTableNameMethod: "TableName",
tagKey: "gorm",
enableGoTidy: false,
enableJsonTag: false,
enableDebug: false,
tableFilterHook: nil,
}
}
func (Output *Config) Username(t string) *Config {
Output.username = t
return Output
}
func (Output *Config) Password(t string) *Config {
Output.password = t
return Output
}
func (Output *Config) Host(t string) *Config {
Output.host = t
return Output
}
func (Output *Config) Database(t string) *Config {
Output.database = t
return Output
}
func (Output *Config) Port(t int) *Config {
Output.port = t
return Output
}
func (Output *Config) OrmPackageName(t string) *Config {
Output.ormPackageName = t
return Output
}
func (Output *Config) SqlPackageName(t string) *Config {
Output.sqlPackageName = t
return Output
}
func (Output *Config) GinPackageName(t string) *Config {
Output.ginPackageName = t
return Output
}
func (Output *Config) BasePath(t string) *Config {
Output.basePath = t
return Output
}
func (Output *Config) Table(t string) *Config {
Output.table = t
return Output
}
func (Output *Config) RealTableNameMethod(t string) *Config {
Output.realTableNameMethod = t
return Output
}
func (Output *Config) TagKey(t string) *Config {
Output.tagKey = t
return Output
}
func (Output *Config) EnableGoTidy(t bool) *Config {
Output.enableGoTidy = t
return Output
}
func (Output *Config) EnableJsonTag(t bool) *Config {
Output.enableJsonTag = t
return Output
}
func (Output *Config) EnableDebug(t bool) *Config {
Output.enableDebug = t
return Output
}
func (Output *Config) TableFilterHook(t func(string) bool) *Config {
Output.tableFilterHook = t
return Output
}