config.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package utils
  2. import (
  3. "fmt"
  4. beeLogger "github.com/beego/bee/v2/logger"
  5. "github.com/beego/beego/v2/server/web"
  6. "github.com/rdlucklib/rdluck_tools/cache"
  7. "strconv"
  8. )
  9. var (
  10. RunMode string //运行模式
  11. MYSQL_URL string //数据库连接
  12. MYSQL_WEEKLY_URL string //用户主库
  13. REDIS_CACHE string //缓存地址
  14. Rc *cache.Cache //redis缓存
  15. Re error //redis错误
  16. )
  17. var (
  18. STATIC_DIR string
  19. )
  20. var (
  21. DATA_INDEX_NAME string //数据指标库索引
  22. )
  23. // 日志配置
  24. var (
  25. LogPath string //调用过程中的日志存放地址
  26. LogFile string
  27. BinLogPath string //数据库相关的日志存放地址
  28. BinLogFile string
  29. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  30. ApiLogFile string
  31. LogMaxDays int //日志最大保留天数
  32. )
  33. func init() {
  34. tmpRunMode, err := web.AppConfig.String("run_mode")
  35. if err != nil {
  36. panic("配置文件读取run_mode错误 " + err.Error())
  37. }
  38. RunMode = tmpRunMode
  39. fmt.Println("RunMode:", RunMode)
  40. if RunMode == "" {
  41. localIp, err := GetLocalIP()
  42. if localIp == "10.0.0.123" {
  43. RunMode = "debug"
  44. } else {
  45. RunMode = "release"
  46. }
  47. configPath := `/home/code/config/eta_data_push/conf/app.conf`
  48. err = web.LoadAppConfig("ini", configPath)
  49. if err != nil {
  50. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  51. }
  52. }
  53. config, err := web.AppConfig.GetSection(RunMode)
  54. if err != nil {
  55. panic("配置文件读取错误 " + err.Error())
  56. }
  57. beeLogger.Log.Info(RunMode + " 模式")
  58. MYSQL_URL = config["mysql_url"]
  59. // 用户主库
  60. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  61. REDIS_CACHE = config["beego_cache"]
  62. if len(REDIS_CACHE) <= 0 {
  63. panic("redis链接参数没有配置")
  64. }
  65. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  66. if Re != nil {
  67. fmt.Println(Re)
  68. panic(Re)
  69. }
  70. if RunMode == "release" {
  71. } else {
  72. }
  73. //日志配置
  74. {
  75. LogPath = config["log_path"]
  76. LogFile = config["log_file"]
  77. BinLogPath = config["binlog_path"]
  78. BinLogFile = config["binlog_file"]
  79. ApiLogPath = config["apilog_path"]
  80. ApiLogFile = config["apilog_file"]
  81. logMaxDaysStr := config["log_max_day"]
  82. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  83. }
  84. }
  85. //修改接口文档
  86. //http://8.136.199.33:8300/swagger/