config.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. LogPath string //调用过程中的日志存放地址
  17. LogFile string
  18. ApiLogPath string // 接口请求地址和接口返回值日志存放地址
  19. ApiLogFile string
  20. BinLogPath string // 数据库相关的日志存放地址
  21. BinLogFile string
  22. LogMaxDays int // 日志最大保留天数
  23. )
  24. // 小程序服务通信密钥
  25. var (
  26. ETA_MINI_API_APPID string
  27. ETA_MINI_API_SECRET string
  28. )
  29. // 微信相关
  30. var (
  31. WX_MINI_APPID string
  32. WX_MINI_APP_SECRET string
  33. DW_WX_Id string //微信原始ID
  34. DW_WX_APPID string
  35. DW_WX_APP_SECRET string
  36. TEMPLATE_ID_BY_PRODUCT string
  37. )
  38. func init() {
  39. tmpRunMode, err := web.AppConfig.String("run_mode")
  40. if err != nil {
  41. panic(any("配置文件读取run_mode错误 " + err.Error()))
  42. }
  43. RunMode = tmpRunMode
  44. fmt.Println("RunMode:", RunMode)
  45. config, err := web.AppConfig.GetSection(RunMode)
  46. if err != nil {
  47. panic(any("配置文件读取错误 " + err.Error()))
  48. }
  49. beeLogger.Log.Info(RunMode + " 模式")
  50. ETA_MINI_API_APPID = config["eta_mini_api_appid"]
  51. ETA_MINI_API_SECRET = config["eta_mini_api_secret"]
  52. // 数据库配置
  53. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  54. MYSQL_URL_MASTER = config["mysql_url_master"]
  55. // 微信配置
  56. WX_MINI_APPID = config["wx_mini_appid"]
  57. WX_MINI_APP_SECRET = config["wx_mini_app_secret"]
  58. DW_WX_Id = config["dw_wx_id"]
  59. DW_WX_APPID = config["dw_wx_appid"]
  60. DW_WX_APP_SECRET = config["dw_wx_app_secret"]
  61. TEMPLATE_ID_BY_PRODUCT = config["template_id_by_product"]
  62. // redis缓存配置
  63. REDIS_CACHE = config["beego_cache"]
  64. if len(REDIS_CACHE) <= 0 {
  65. panic(any("redis链接参数没有配置"))
  66. }
  67. // 初始化缓存
  68. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  69. if err != nil {
  70. fmt.Println("redis链接异常:", err)
  71. panic(any("redis链接参数没有配置"))
  72. }
  73. Rc = redisClient
  74. }