forked from GoAdminGroup/go-admin
/
config.go
126 lines (109 loc) · 2.42 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
125
126
package table
import (
"github.com/GoAdminGroup/go-admin/modules/db"
)
type Config struct {
Driver string
Connection string
CanAdd bool
Editable bool
Deletable bool
Exportable bool
PrimaryKey PrimaryKey
SourceURL string
GetDataFun GetDataFun
OnlyInfo bool
OnlyNewForm bool
OnlyUpdateForm bool
OnlyDetail bool
}
func DefaultConfig() Config {
return Config{
Driver: db.DriverMysql,
CanAdd: true,
Editable: true,
Deletable: true,
Exportable: true,
Connection: DefaultConnectionName,
PrimaryKey: PrimaryKey{
Type: db.Int,
Name: DefaultPrimaryKeyName,
},
}
}
func (config Config) SetPrimaryKeyType(typ string) Config {
config.PrimaryKey.Type = db.GetDTAndCheck(typ)
return config
}
func (config Config) SetCanAdd(canAdd bool) Config {
config.CanAdd = canAdd
return config
}
func (config Config) SetSourceURL(url string) Config {
config.SourceURL = url
return config
}
func (config Config) SetGetDataFun(fun GetDataFun) Config {
config.GetDataFun = fun
return config
}
func (config Config) SetEditable(editable bool) Config {
config.Editable = editable
return config
}
func (config Config) SetDeletable(deletable bool) Config {
config.Deletable = deletable
return config
}
func (config Config) SetOnlyInfo() Config {
config.OnlyInfo = true
return config
}
func (config Config) SetOnlyUpdateForm() Config {
config.OnlyUpdateForm = true
return config
}
func (config Config) SetOnlyNewForm() Config {
config.OnlyNewForm = true
return config
}
func (config Config) SetOnlyDetail() Config {
config.OnlyDetail = true
return config
}
func (config Config) SetExportable(exportable bool) Config {
config.Exportable = exportable
return config
}
func (config Config) SetConnection(connection string) Config {
config.Connection = connection
return config
}
func DefaultConfigWithDriver(driver string) Config {
return Config{
Driver: driver,
Connection: DefaultConnectionName,
CanAdd: true,
Editable: true,
Deletable: true,
Exportable: true,
PrimaryKey: PrimaryKey{
Type: db.Int,
Name: DefaultPrimaryKeyName,
},
}
}
func DefaultConfigWithDriverAndConnection(driver, conn string) Config {
return Config{
Driver: driver,
Connection: conn,
CanAdd: true,
Editable: true,
Deletable: true,
Exportable: true,
PrimaryKey: PrimaryKey{
Type: db.Int,
Name: DefaultPrimaryKeyName,
},
}
}