config.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package utils
  2. import (
  3. "fmt"
  4. beeLogger "github.com/beego/bee/v2/logger"
  5. "github.com/beego/beego/v2/server/web"
  6. "strconv"
  7. )
  8. var (
  9. RunMode string //运行模式
  10. MYSQL_URL string //数据库连接
  11. MYSQL_URL_DATA string
  12. MYSQL_URL_RDDP string
  13. )
  14. // 日志配置
  15. var (
  16. LogPath string //调用过程中的日志存放地址
  17. LogFile string
  18. BinLogPath string //数据库相关的日志存放地址
  19. BinLogFile string
  20. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  21. ApiLogFile string
  22. LogMaxDays int //日志最大保留天数
  23. )
  24. var (
  25. BusinessCode string //商家编码
  26. AppId string
  27. Secret string
  28. )
  29. // ES索引配置
  30. var (
  31. EsReportIndexName string //研报ES索引
  32. SmartReportIndexName string //智能研报ES索引
  33. )
  34. // ES配置
  35. var (
  36. ES_URL string // ES服务器地址
  37. ES_USERNAME string // ES账号
  38. ES_PASSWORD string // ES密码
  39. )
  40. func init() {
  41. tmpRunMode, err := web.AppConfig.String("run_mode")
  42. if err != nil {
  43. panic("配置文件读取run_mode错误 " + err.Error())
  44. }
  45. RunMode = tmpRunMode
  46. if RunMode == "" {
  47. localIp, err := GetLocalIP()
  48. fmt.Println("localIp:", localIp)
  49. if localIp == "10.0.0.123" {
  50. RunMode = "debug"
  51. } else {
  52. RunMode = "release"
  53. }
  54. configPath := `/home/code/config/eta_hub/conf/app.conf`
  55. err = web.LoadAppConfig("ini", configPath)
  56. if err != nil {
  57. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  58. }
  59. }
  60. config, err := web.AppConfig.GetSection(RunMode)
  61. if err != nil {
  62. panic("配置文件读取错误 " + err.Error())
  63. }
  64. beeLogger.Log.Info(RunMode + " 模式")
  65. MYSQL_URL = config["mysql_url"]
  66. MYSQL_URL_DATA = config["mysql_url_data"]
  67. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  68. if RunMode == "release" {
  69. } else {
  70. }
  71. //商家编码
  72. BusinessCode = config["business_code"]
  73. if BusinessCode == "" {
  74. panic("商家编码未配置,请先配置商家编码")
  75. }
  76. AppId = config["appid"]
  77. if AppId == "" {
  78. panic("appid未配置")
  79. }
  80. Secret = config["secret"]
  81. if Secret == "" {
  82. panic("secret未配置")
  83. }
  84. //日志配置
  85. {
  86. LogPath = config["log_path"]
  87. LogFile = config["log_file"]
  88. BinLogPath = config["binlog_path"]
  89. BinLogFile = config["binlog_file"]
  90. ApiLogPath = config["apilog_path"]
  91. ApiLogFile = config["apilog_file"]
  92. logMaxDaysStr := config["log_max_day"]
  93. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  94. }
  95. // ES 索引
  96. {
  97. EsReportIndexName = config["es_report_index_name"]
  98. SmartReportIndexName = config["es_smart_report_index_name"]
  99. }
  100. // ES配置
  101. {
  102. ES_URL = config["es_url"]
  103. ES_USERNAME = config["es_username"]
  104. ES_PASSWORD = config["es_password"]
  105. }
  106. }