config.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package utils
  2. import (
  3. "fmt"
  4. beeLogger "github.com/beego/bee/v2/logger"
  5. "github.com/beego/beego/v2/server/web"
  6. )
  7. // 数据库配置
  8. var (
  9. RunMode string // 运行模式
  10. MYSQL_URL_MASTER string // 数据库地址
  11. MYSQL_URL_RDDP string // 数据库地址
  12. REDIS_CACHE string //缓存地址
  13. Rc RedisClient //redis缓存
  14. )
  15. var (
  16. ApiLogPath string // 接口请求地址和接口返回值日志存放地址
  17. ApiLogFile string
  18. BinLogPath string // 数据库相关的日志存放地址
  19. BinLogFile string
  20. LogMaxDays int // 日志最大保留天数
  21. )
  22. var DesKey string // 接口返回加密KEY
  23. func init() {
  24. tmpRunMode, err := web.AppConfig.String("run_mode")
  25. if err != nil {
  26. panic(any("配置文件读取run_mode错误 " + err.Error()))
  27. }
  28. RunMode = tmpRunMode
  29. fmt.Println("RunMode:", RunMode)
  30. config, err := web.AppConfig.GetSection(RunMode)
  31. if err != nil {
  32. panic(any("配置文件读取错误 " + err.Error()))
  33. }
  34. beeLogger.Log.Info(RunMode + " 模式")
  35. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  36. MYSQL_URL_MASTER = config["mysql_url_master"]
  37. REDIS_CACHE = config["beego_cache"]
  38. if len(REDIS_CACHE) <= 0 {
  39. panic(any("redis链接参数没有配置"))
  40. }
  41. // 初始化缓存
  42. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  43. if err != nil {
  44. fmt.Println("redis链接异常:", err)
  45. panic(any("redis链接参数没有配置"))
  46. }
  47. Rc = redisClient
  48. }