config.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. )
  8. var (
  9. RunMode string //运行模式
  10. MYSQL_URL string //数据库连接
  11. MYSQL_URL_DATA string
  12. MYSQL_URL_EDB string
  13. REDIS_CACHE string //缓存地址
  14. Rc *cache.Cache //redis缓存
  15. Re error //redis错误
  16. )
  17. // 基础配置
  18. var (
  19. // SystemType 系统类型; hz:弘则;trial:试用平台;custom:客户
  20. SystemType string
  21. // APPNAME 项目中文名称
  22. APPNAME string
  23. // EmailSendToUsers 邮件提醒人员
  24. EmailSendToUsers string
  25. // AlarmMsgUrl 报警服务地址
  26. AlarmMsgUrl string
  27. )
  28. // 公共api内部服务调用
  29. var (
  30. // EDB_LIB_URL 公共指标库
  31. EDB_LIB_URL string
  32. APP_EDB_LIB_NAME_EN string
  33. EDB_LIB_Md5_KEY string
  34. )
  35. var (
  36. LogPath string
  37. LogFile string
  38. BinLogPath string
  39. BinLogFile string
  40. ApiLogPath string
  41. ApiLogFile string
  42. )
  43. func init() {
  44. tmpRunMode, err := web.AppConfig.String("run_mode")
  45. if err != nil {
  46. panic("配置文件读取run_mode错误 " + err.Error())
  47. }
  48. RunMode = tmpRunMode
  49. if RunMode == "" {
  50. localIp, err := GetLocalIP()
  51. if localIp == "10.0.0.123" {
  52. RunMode = "debug"
  53. } else {
  54. RunMode = "release"
  55. }
  56. configPath := `/home/code/config/eta_chart_lib/conf/app.conf`
  57. err = web.LoadAppConfig("ini", configPath)
  58. if err != nil {
  59. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  60. }
  61. }
  62. config, err := web.AppConfig.GetSection(RunMode)
  63. if err != nil {
  64. panic("配置文件读取错误 " + err.Error())
  65. }
  66. beeLogger.Log.Info(RunMode + " 模式")
  67. MYSQL_URL = config["mysql_url"]
  68. MYSQL_URL_DATA = config["mysql_url_data"]
  69. MYSQL_URL_EDB = config["mysql_url_edb"]
  70. REDIS_CACHE = config["beego_cache"]
  71. if len(REDIS_CACHE) <= 0 {
  72. panic("redis链接参数没有配置")
  73. }
  74. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  75. if Re != nil {
  76. fmt.Println(Re)
  77. panic(Re)
  78. }
  79. // 系统类型
  80. systemType, err := web.AppConfig.String("system_type")
  81. if err != nil {
  82. panic(any("配置文件读取system_type错误 " + err.Error()))
  83. }
  84. SystemType = systemType
  85. // 项目中文名称
  86. appNameCn, err := web.AppConfig.String("app_name_cn")
  87. if err != nil {
  88. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  89. }
  90. APPNAME = appNameCn
  91. // 邮件提醒人员
  92. EmailSendToUsers = config["email_send_to_users"]
  93. // 报警服务地址
  94. AlarmMsgUrl = config["alarm_msg_url"]
  95. // 公共api内部服务调用
  96. {
  97. // 公共指标库相关
  98. EDB_LIB_URL = config["edb_lib_url"]
  99. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  100. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  101. }
  102. //日志配置
  103. {
  104. LogPath = config["log_path"]
  105. LogFile = config["log_file"]
  106. BinLogPath = config["binlog_path"]
  107. BinLogFile = config["binlog_file"]
  108. ApiLogPath = config["apilog_path"]
  109. ApiLogFile = config["apilog_file"]
  110. }
  111. }
  112. //http://8.136.199.33:8608/swagger/
  113. //http://8.136.199.33:8608/v1