upgrade
This commit is contained in:
91
configs/configs.go
Normal file
91
configs/configs.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package configs
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/pkg/env"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var config = new(Config)
|
||||
|
||||
type Config struct {
|
||||
MySQL struct {
|
||||
Read struct {
|
||||
Addr string `toml:"addr"`
|
||||
User string `toml:"user"`
|
||||
Pass string `toml:"pass"`
|
||||
Name string `toml:"name"`
|
||||
} `toml:"read"`
|
||||
Write struct {
|
||||
Addr string `toml:"addr"`
|
||||
User string `toml:"user"`
|
||||
Pass string `toml:"pass"`
|
||||
Name string `toml:"name"`
|
||||
} `toml:"write"`
|
||||
Base struct {
|
||||
MaxOpenConn int `toml:"maxOpenConn"`
|
||||
MaxIdleConn int `toml:"maxIdleConn"`
|
||||
ConnMaxLifeTime time.Duration `toml:"connMaxLifeTime"`
|
||||
} `toml:"base"`
|
||||
} `toml:"mysql"`
|
||||
|
||||
Redis struct {
|
||||
Addr string `toml:"addr"`
|
||||
Pass string `toml:"pass"`
|
||||
Db int `toml:"db"`
|
||||
MaxRetries int `toml:"maxRetries"`
|
||||
PoolSize int `toml:"poolSize"`
|
||||
MinIdleConns int `toml:"minIdleConns"`
|
||||
} `toml:"redis"`
|
||||
|
||||
Mail struct {
|
||||
Host string `toml:"host"`
|
||||
Port int `toml:"port"`
|
||||
User string `toml:"user"`
|
||||
Pass string `toml:"pass"`
|
||||
To string `toml:"to"`
|
||||
} `toml:"mail"`
|
||||
|
||||
JWT struct {
|
||||
Secret string `toml:"secret"`
|
||||
} `toml:"jwt"`
|
||||
|
||||
Aes struct {
|
||||
Key string `toml:"key"`
|
||||
Iv string `toml:"iv"`
|
||||
} `toml:"aes"`
|
||||
|
||||
Rsa struct {
|
||||
Private string `toml:"private"`
|
||||
Public string `toml:"public"`
|
||||
} `toml:"rsa"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
viper.SetConfigName(env.Active().Value() + "_configs")
|
||||
viper.SetConfigType("toml")
|
||||
viper.AddConfigPath("./configs")
|
||||
viper.AddConfigPath("../../configs") // 兼容 cmd/cron/main.go 引用配置文件
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := viper.Unmarshal(config); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func Get() Config {
|
||||
return *config
|
||||
}
|
||||
|
||||
func ProjectName() string {
|
||||
return "go-gin-api"
|
||||
}
|
||||
|
||||
func ProjectVersion() string {
|
||||
return "v2.0"
|
||||
}
|
||||
@@ -1,3 +1,28 @@
|
||||
[mysql]
|
||||
|
||||
[mysql.read]
|
||||
addr = ''
|
||||
user = ''
|
||||
pass = ''
|
||||
name = ''
|
||||
[mysql.write]
|
||||
addr = ''
|
||||
user = ''
|
||||
pass = ''
|
||||
name = ''
|
||||
[mysql.base]
|
||||
maxOpenConn = 10
|
||||
maxIdleConn = 60
|
||||
connMaxLifeTime = 60
|
||||
|
||||
[redis]
|
||||
addr = ''
|
||||
pass = ''
|
||||
db = 0
|
||||
maxRetries = 3
|
||||
poolSize = 10
|
||||
minIdleConns = 5
|
||||
|
||||
[mail]
|
||||
host = 'smtp.163.com'
|
||||
port = 465
|
||||
|
||||
Reference in New Issue
Block a user