This commit is contained in:
2024-12-23 18:34:46 +08:00
commit cbfcc91eec
24 changed files with 1702 additions and 0 deletions

12
config/config.go Normal file
View File

@@ -0,0 +1,12 @@
package config
const (
AppEnv = "dev"
EnvConfig = "config.yaml"
)
type Config struct {
IsDebug bool `mapstructure:"is_debug" json:"is_debug" yaml:"is_debug"`
Db DbConf `mapstructure:"db" json:"db" yaml:"db"`
Service ServiceConf `mapstructure:"service" json:"service" yaml:"service"`
}

15
config/db.go Normal file
View File

@@ -0,0 +1,15 @@
package config
type DbConf struct {
DbHost string `mapstructure:"db_host" json:"db_host" yaml:"db_host"`
DbPort int `mapstructure:"db_port" json:"db_port" yaml:"db_port"`
DbName string `mapstructure:"db_name" json:"db_name" yaml:"db_name"`
DbUser string `mapstructure:"db_user" json:"db_user" yaml:"db_user"`
DbPass string `mapstructure:"db_pass" json:"db_pass" yaml:"db_pass"`
TablePrefix string `mapstructure:"table_prefix" json:"table_prefix" yaml:"table_prefix"`
TimeZone string `mapstructure:"time_zone" json:"time_zone" yaml:"time_zone"`
LogLevel int `mapstructure:"log_level" json:"log_level" yaml:"log_level"` // LogLevel SQL日志级别 (1-静音 2-错误 3-警告 4-信息)
SlowThreshold int `mapstructure:"slow_threshold" json:"slow_threshold" yaml:"slow_threshold"` // SlowThreshold 慢SQL阈值毫秒。慢SQL会在log_level大于等于3时输出。
IdleConns int `mapstructure:"idle_conns" json:"idle_conns" yaml:"idle_conns"` // 空闲连接池中的最大连接数建议为open_conns的百分之5-20之间
OpenConns int `mapstructure:"open_conns" json:"open_conns" yaml:"open_conns"` // 最大打开连接数建议这里设置为50
}

15
config/service.go Normal file
View File

@@ -0,0 +1,15 @@
package config
type ServiceConf struct {
Http HttpConf `mapstructure:"http" json:"http" yaml:"http"`
Tcp TcpConf `mapstructure:"tcp" json:"tcp" yaml:"tcp"`
}
type HttpConf struct {
Host string `mapstructure:"host" json:"host" yaml:"host"`
Port string `mapstructure:"port" json:"port" yaml:"port"`
}
type TcpConf struct {
Host string `mapstructure:"host" json:"host" yaml:"host"`
Port string `mapstructure:"port" json:"port" yaml:"port"`
}