This commit is contained in:
2024-08-26 17:20:13 +08:00
commit 51090658a2
39 changed files with 2231 additions and 0 deletions

19
config/config.go Normal file
View File

@@ -0,0 +1,19 @@
package config
//环境 全称 简写
//开发环境 development dev
//测试环境 testing test
//灰度/预发布环境 staging/pre-production stag
//生产环境 production prod
const (
// AppEnv 应用环境 dev,test,stag,prod
AppEnv = "dev"
// EnvConfig 环境配置
EnvConfig = "config.yaml"
)
type Config struct {
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
}

10
config/service.go Normal file
View File

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