[🚀] mapstructure
This commit is contained in:
@@ -49,45 +49,41 @@ type DBStats struct {
|
||||
Write sql.DBStats `json:"write"`
|
||||
}
|
||||
|
||||
// MySQLConfig MySQL配置
|
||||
type MySQLConfig struct {
|
||||
Read DBConnConfig `yaml:"read" json:"read"`
|
||||
Write DBConnConfig `yaml:"write" json:"write"`
|
||||
Base BaseConfig `yaml:"base" json:"base"`
|
||||
Logger LoggerConfig `yaml:"logger" json:"logger"`
|
||||
Read DBConnConfig `yaml:"read" json:"read" mapstructure:"read"`
|
||||
Write DBConnConfig `yaml:"write" json:"write" mapstructure:"write"`
|
||||
Base BaseConfig `yaml:"base" json:"base" mapstructure:"base"`
|
||||
Logger LoggerConfig `yaml:"logger" json:"logger" mapstructure:"logger"`
|
||||
}
|
||||
|
||||
// DBConnConfig 数据库连接配置
|
||||
type DBConnConfig struct {
|
||||
Addr string `yaml:"addr" json:"addr"`
|
||||
User string `yaml:"user" json:"user"`
|
||||
Pass string `yaml:"pass" json:"pass"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Charset string `yaml:"charset" json:"charset"` // 默认 utf8mb4
|
||||
Collation string `yaml:"collation" json:"collation"` // 默认 utf8mb4_unicode_ci
|
||||
Loc string `yaml:"loc" json:"loc"` // 默认 Local
|
||||
ParseTime bool `yaml:"parse_time" json:"parse_time"` // 默认 true
|
||||
Timeout time.Duration `yaml:"timeout" json:"timeout"` // 连接超时(秒)
|
||||
ReadTimeout time.Duration `yaml:"read_timeout" json:"read_timeout"` // 读超时(秒)
|
||||
WriteTimeout time.Duration `yaml:"write_timeout" json:"write_timeout"` // 写超时(秒)
|
||||
Addr string `yaml:"addr" json:"addr" mapstructure:"addr"`
|
||||
User string `yaml:"user" json:"user" mapstructure:"user"`
|
||||
Pass string `yaml:"pass" json:"pass" mapstructure:"pass"`
|
||||
Name string `yaml:"name" json:"name" mapstructure:"name"`
|
||||
Charset string `yaml:"charset" json:"charset" mapstructure:"charset"`
|
||||
Collation string `yaml:"collation" json:"collation" mapstructure:"collation"`
|
||||
Loc string `yaml:"loc" json:"loc" mapstructure:"loc"`
|
||||
ParseTime bool `yaml:"parse_time" json:"parse_time" mapstructure:"parse_time"`
|
||||
Timeout time.Duration `yaml:"timeout" json:"timeout" mapstructure:"timeout"`
|
||||
ReadTimeout time.Duration `yaml:"read_timeout" json:"read_timeout" mapstructure:"read_timeout"`
|
||||
WriteTimeout time.Duration `yaml:"write_timeout" json:"write_timeout" mapstructure:"write_timeout"`
|
||||
}
|
||||
|
||||
// BaseConfig 基础配置
|
||||
type BaseConfig struct {
|
||||
MaxOpenConn int `yaml:"max_open_conn" json:"max_open_conn"`
|
||||
MaxIdleConn int `yaml:"max_idle_conn" json:"max_idle_conn"`
|
||||
ConnMaxLifetime time.Duration `yaml:"conn_max_lifetime" json:"conn_max_lifetime"` // 秒
|
||||
ConnMaxIdleTime time.Duration `yaml:"conn_max_idle_time" json:"conn_max_idle_time"` // 秒
|
||||
MaxOpenConn int `yaml:"max_open_conn" json:"max_open_conn" mapstructure:"max_open_conn"`
|
||||
MaxIdleConn int `yaml:"max_idle_conn" json:"max_idle_conn" mapstructure:"max_idle_conn"`
|
||||
ConnMaxLifetime time.Duration `yaml:"conn_max_lifetime" json:"conn_max_lifetime" mapstructure:"conn_max_lifetime"`
|
||||
ConnMaxIdleTime time.Duration `yaml:"conn_max_idle_time" json:"conn_max_idle_time" mapstructure:"conn_max_idle_time"`
|
||||
}
|
||||
|
||||
// LoggerConfig 日志配置
|
||||
type LoggerConfig struct {
|
||||
SlowThreshold time.Duration `yaml:"slow_threshold" json:"slow_threshold"`
|
||||
Colorful bool `yaml:"colorful" json:"colorful"`
|
||||
IgnoreRecordNotFoundError bool `yaml:"ignore_record_not_found_error" json:"ignore_record_not_found_error"`
|
||||
LogLevel string `yaml:"log_level" json:"log_level"`
|
||||
LogOutput string `yaml:"log_output" json:"log_output"` // stdout, file
|
||||
LogFile string `yaml:"log_file" json:"log_file"` // 日志文件路径
|
||||
SlowThreshold time.Duration `yaml:"slow_threshold" json:"slow_threshold" mapstructure:"slow_threshold"`
|
||||
Colorful bool `yaml:"colorful" json:"colorful" mapstructure:"colorful"`
|
||||
IgnoreRecordNotFoundError bool `yaml:"ignore_record_not_found_error" json:"ignore_record_not_found_error" mapstructure:"ignore_record_not_found_error"`
|
||||
LogLevel string `yaml:"log_level" json:"log_level" mapstructure:"log_level"`
|
||||
LogOutput string `yaml:"log_output" json:"log_output" mapstructure:"log_output"`
|
||||
LogFile string `yaml:"log_file" json:"log_file" mapstructure:"log_file"`
|
||||
}
|
||||
|
||||
// DefaultMySQLConfig 默认配置
|
||||
|
||||
Reference in New Issue
Block a user