-
Notifications
You must be signed in to change notification settings - Fork 14
/
config_builder.go
103 lines (83 loc) · 1.85 KB
/
config_builder.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
package gobatis
type DataSourceBuilder struct {
ds *DataSource
}
func NewDataSourceBuilder() *DataSourceBuilder {
return &DataSourceBuilder{
ds: &DataSource{},
}
}
// DataSource
func (d *DataSourceBuilder) DataSource(ds string) *DataSourceBuilder {
d.ds.DataSource = ds
return d
}
// DriverName
func (d *DataSourceBuilder) DriverName(dn string) *DataSourceBuilder {
d.ds.DriverName = dn
return d
}
// DataSourceName
func (d *DataSourceBuilder) DataSourceName(dsn string) *DataSourceBuilder {
d.ds.DataSourceName = dsn
return d
}
// MaxLifeTime
func (d *DataSourceBuilder) MaxLifeTime(mlt int) *DataSourceBuilder {
d.ds.MaxLifeTime = mlt
return d
}
// MaxOpenConns
func (d *DataSourceBuilder) MaxOpenConns(moc int) *DataSourceBuilder {
d.ds.MaxOpenConns = moc
return d
}
// MaxIdleConns
func (d *DataSourceBuilder) MaxIdleConns(mic int) *DataSourceBuilder {
d.ds.MaxIdleConns = mic
return d
}
func (d *DataSourceBuilder) Build() *DataSource {
if d.ds.DataSource == "" {
panic("DataSource is nil")
}
if d.ds.DataSourceName == "" {
panic("DataSourceName is nil")
}
if d.ds.DriverName == "" {
panic("DriverName is nil")
}
return d.ds
}
type DBConfigBuilder struct {
d *DBConfig
}
func NewDBConfigBuilder() *DBConfigBuilder {
return &DBConfigBuilder{
d: &DBConfig{
DB: make([]*DataSource, 0),
},
}
}
func (d *DBConfigBuilder) Mappers(mappers []string) *DBConfigBuilder {
d.d.Mappers = mappers
return d
}
func (d *DBConfigBuilder) DS(dss []*DataSource) *DBConfigBuilder {
d.d.DB = dss
return d
}
func (d *DBConfigBuilder) DB(db map[string]*GoBatisDB) *DBConfigBuilder {
d.d.db = db
return d
}
func (d *DBConfigBuilder) ShowSQL(showSQL bool) *DBConfigBuilder {
d.d.ShowSQL = showSQL
return d
}
func (d *DBConfigBuilder) Build() *DBConfig {
if len(d.d.DB) <= 0 && d.d.db == nil {
panic("No config for datasource")
}
return d.d
}