changes
This commit is contained in:
parent
01cd6d8e01
commit
3e9ac30812
1
.idea/database.iml
generated
1
.idea/database.iml
generated
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
|
45
config_builder.go
Normal file
45
config_builder.go
Normal file
@ -0,0 +1,45 @@
|
||||
package database
|
||||
|
||||
type ConfigBuilder struct {
|
||||
config *Config
|
||||
}
|
||||
|
||||
func NewConfigBuilder() *ConfigBuilder {
|
||||
return &ConfigBuilder{
|
||||
config: NewConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
func (cb *ConfigBuilder) DSN(dsn string) *ConfigBuilder {
|
||||
cb.config.DSN = dsn
|
||||
return cb
|
||||
}
|
||||
|
||||
func (cb *ConfigBuilder) MaxIdleConns(maxIdleConns int) *ConfigBuilder {
|
||||
cb.config.MaxIdleConns = maxIdleConns
|
||||
return cb
|
||||
}
|
||||
|
||||
func (cb *ConfigBuilder) MaxOpenConns(maxOpenConns int) *ConfigBuilder {
|
||||
cb.config.MaxOpenConns = maxOpenConns
|
||||
return cb
|
||||
}
|
||||
|
||||
func (cb *ConfigBuilder) ConnMaxLifetime(connMaxLifetime int) *ConfigBuilder {
|
||||
cb.config.ConnMaxLifetime = connMaxLifetime
|
||||
return cb
|
||||
}
|
||||
|
||||
func (cb *ConfigBuilder) AutoMigrate(autoMigrate bool) *ConfigBuilder {
|
||||
cb.config.AutoMigrate = autoMigrate
|
||||
return cb
|
||||
}
|
||||
|
||||
func (cb *ConfigBuilder) ShowSQL(showSql bool) *ConfigBuilder {
|
||||
cb.config.ShowSql = showSql
|
||||
return cb
|
||||
}
|
||||
|
||||
func (cb *ConfigBuilder) Build() *Config {
|
||||
return cb.config
|
||||
}
|
2
go.mod
2
go.mod
@ -2,7 +2,7 @@ module netgarden.dev/maf/database
|
||||
|
||||
go 1.24.1
|
||||
|
||||
replace netgarden.dev/maf/maf => ../maf
|
||||
replace netgarden.dev/maf/maf => ../../maf/maf
|
||||
|
||||
require (
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
|
11
module.go
11
module.go
@ -10,7 +10,13 @@ import (
|
||||
)
|
||||
|
||||
func NewModule() *Module {
|
||||
return &Module{}
|
||||
return NewModuleWithConfig(NewConfig())
|
||||
}
|
||||
|
||||
func NewModuleWithConfig(config *Config) *Module {
|
||||
return &Module{
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
type Module struct {
|
||||
@ -32,6 +38,9 @@ func (m *Module) SetManager(manager *maf.Manager) {
|
||||
}
|
||||
|
||||
func (m *Module) CreateConfig() interface{} {
|
||||
if m.config != nil {
|
||||
return m.config
|
||||
}
|
||||
return NewConfig()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user