123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package config
- import (
- "crypto/rsa"
- "os"
- "strings"
- "sync"
- "gitee.com/xuyiping_admin/pkg/di"
- )
- var (
- Module = di.Provide(Options)
- options *AppConfig
- appEnv string
- initOnce sync.Once
- )
- // AppConfig store all configuration options
- type AppConfig struct {
- AppName string `yaml:"app_name"`
- AppEnv string `yaml:"app_environment"`
- Debug bool `yaml:"debug" env:"APP_DEBUG"`
- HTTPServerAddr string `yaml:"http_server_addr" env:"HTTP_SERVER_ADDR"`
- // 数据库配置 额外加载文件部分 database.yaml
- StoreSetting StoreSetting `json:"storeSetting" yaml:"store"`
- // redis 配置
- RedisSetting RedisSetting `json:"RedisSetting" yaml:"redis_setting"`
- JwtSecret string `json:"jwtSecret" yaml:"jwt_secret"`
- ExcelSetting ExcelSetting `json:"excelSetting" yaml:"excel_setting"`
- WechatSetting WechatSetting `json:"wechatSetting" yaml:"wechat_setting"`
- JwtTokenKeyConfig JwtTokenKeyConfig `json:"jwtTokenKeyConfig"`
- JwtExpireTime int `json:"jwtExpireTime" yaml:"jwt_expire_time"`
- }
- type JwtTokenKeyConfig struct {
- PrivateKey *rsa.PrivateKey `json:"privateKey"`
- PublicKey *rsa.PublicKey `json:"publicKey"`
- }
- type WechatSetting struct {
- Appid string `yaml:"appid"`
- Secret string `yaml:"secret"`
- }
- type ExcelSetting struct {
- SheetName string `yaml:"sheet_name"` // = "Sheet1" //默认Sheet名称
- Height float64 `yaml:"height"` // = 25.0 //默认行高度
- }
- // StoreSetting 数据库配置
- type StoreSetting struct {
- // 开启 SyDb SQL 记录
- DriverName string `yaml:"driver_name" json:"driver_name"`
- ShowSQL bool `yaml:"show_sql" json:"show_sql"`
- KptRW string `yaml:"kpt_rw" json:"kpt_rw"`
- KptMigr string `yaml:"kpt_migr" json:"kpt_migr"`
- }
- type RedisSetting struct {
- // sso 配置
- SSOCache SSOCache `json:"SSOCache" yaml:"sso_cache"`
- }
- type SSOCache struct {
- Addr string `json:"addr" yaml:"addr"`
- Requirepass string `json:"requirepass" yaml:"requirepass"`
- DB int `json:"DB" yaml:"DB"`
- Expiry int `json:"expiry" yaml:"expiry"`
- }
- func Options() *AppConfig {
- return options
- }
- func init() {
- appEnv = strings.ToLower(os.Getenv("APP_ENVIRONMENT"))
- cfg := &AppConfig{}
- var err error
- initOnce.Do(func() {
- switch appEnv {
- case "test":
- err = Initialize("app.test.yaml", cfg)
- case "development":
- err = Initialize("app.develop.yaml", cfg)
- case "production":
- err = Initialize("app.production.yaml", cfg)
- default:
- panic("err confing")
- }
- if err != nil {
- panic(err)
- }
- cfg.JwtTokenKeyConfig = openPrivateKey()
- options = cfg
- })
- }
|