feat: 添加服务和数据库初始化
This commit is contained in:
@@ -18,6 +18,8 @@ type Config struct {
|
||||
Server ServerConfig `mapstructure:"server"`
|
||||
App AppConfig `mapstructure:"app"`
|
||||
Log LogConfig `mapstructure:"log"`
|
||||
MySQL MySQLConfig `mapstructure:"mysql"`
|
||||
Redis RedisConfig `mapstructure:"redis"`
|
||||
}
|
||||
|
||||
// ServerConfig represents server configuration
|
||||
@@ -44,6 +46,33 @@ type LogConfig struct {
|
||||
Compress bool `mapstructure:"compress"`
|
||||
}
|
||||
|
||||
// MySQLConfig represents mysql configuration
|
||||
type MySQLConfig struct {
|
||||
Host string `mapstructure:"host"`
|
||||
Port int `mapstructure:"port"`
|
||||
User string `mapstructure:"user"`
|
||||
Password string `mapstructure:"password"`
|
||||
DBName string `mapstructure:"db_name"`
|
||||
Charset string `mapstructure:"charset"`
|
||||
ParseTime bool `mapstructure:"parse_time"`
|
||||
MaxIdleConns int `mapstructure:"max_idle_conns"`
|
||||
MaxOpenConns int `mapstructure:"max_open_conns"`
|
||||
ConnMaxLifetime int `mapstructure:"conn_max_lifetime"` // seconds
|
||||
}
|
||||
|
||||
// RedisConfig represents redis configuration
|
||||
type RedisConfig struct {
|
||||
Addr string `mapstructure:"addr"`
|
||||
Password string `mapstructure:"password"`
|
||||
DB int `mapstructure:"db"`
|
||||
PoolSize int `mapstructure:"pool_size"`
|
||||
MinIdleConns int `mapstructure:"min_idle_conns"`
|
||||
MaxRetries int `mapstructure:"max_retries"`
|
||||
DialTimeout int `mapstructure:"dial_timeout"` // seconds
|
||||
ReadTimeout int `mapstructure:"read_timeout"` // seconds
|
||||
WriteTimeout int `mapstructure:"write_timeout"` // seconds
|
||||
}
|
||||
|
||||
// Load loads configuration from environment variable CFG_PATH
|
||||
// Default path is config/config.yml
|
||||
func Load() (*Config, error) {
|
||||
@@ -94,6 +123,29 @@ func Get() *Config {
|
||||
MaxAge: 28,
|
||||
Compress: true,
|
||||
},
|
||||
MySQL: MySQLConfig{
|
||||
Host: "127.0.0.1",
|
||||
Port: 3306,
|
||||
User: "root",
|
||||
Password: "",
|
||||
DBName: "test",
|
||||
Charset: "utf8mb4",
|
||||
ParseTime: true,
|
||||
MaxIdleConns: 10,
|
||||
MaxOpenConns: 100,
|
||||
ConnMaxLifetime: 3600,
|
||||
},
|
||||
Redis: RedisConfig{
|
||||
Addr: "127.0.0.1:6379",
|
||||
Password: "",
|
||||
DB: 0,
|
||||
PoolSize: 10,
|
||||
MinIdleConns: 5,
|
||||
MaxRetries: 3,
|
||||
DialTimeout: 5,
|
||||
ReadTimeout: 3,
|
||||
WriteTimeout: 3,
|
||||
},
|
||||
}
|
||||
}
|
||||
return globalConfig
|
||||
|
||||
Reference in New Issue
Block a user