|
|
@@ -20,17 +20,24 @@ type dsnConfig struct { |
|
|
|
} |
|
|
|
|
|
|
|
type DbItem struct { |
|
|
|
User string `yaml:"user"` |
|
|
|
Pass string `yaml:"pass"` |
|
|
|
Host string `yaml:"host"` |
|
|
|
Port int `yaml:"port"` |
|
|
|
Name string `yaml:"name"` |
|
|
|
Driver string `yaml:"driver"` |
|
|
|
Prefix string `yaml:"prefix"` |
|
|
|
User string `yaml:"user"` |
|
|
|
Pass string `yaml:"pass"` |
|
|
|
Host string `yaml:"host"` |
|
|
|
Port int `yaml:"port"` |
|
|
|
Name string `yaml:"name"` |
|
|
|
Driver string `yaml:"driver"` |
|
|
|
Prefix string `yaml:"prefix"` |
|
|
|
MaxIdleConns int `yaml:"max_idle_conns"` |
|
|
|
MaxOpenConns int `yaml:"max_open_conns"` |
|
|
|
ConnMaxLifetime int64 `yaml:"conn_max_lifetime"` |
|
|
|
Timeout int `yaml:"timeout"` |
|
|
|
} |
|
|
|
|
|
|
|
func (d *DbItem) Dsn() string { |
|
|
|
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&loc=Local&autocommit=true&timeout=5s", d.User, d.Pass, d.Host, d.Port, d.Name) |
|
|
|
if d.Timeout <= 0 { |
|
|
|
d.Timeout = 5 |
|
|
|
} |
|
|
|
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&loc=Local&autocommit=true&timeout=%ds", d.User, d.Pass, d.Host, d.Port, d.Name, d.Timeout) |
|
|
|
} |
|
|
|
|
|
|
|
func init() { |
|
|
|