config.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_RDDP string
  12. )
  13. // 日志配置
  14. var (
  15. LogPath string //调用过程中的日志存放地址
  16. LogFile string
  17. BinLogPath string //数据库相关的日志存放地址
  18. BinLogFile string
  19. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  20. ApiLogFile string
  21. LogMaxDays int //日志最大保留天数
  22. )
  23. // ES索引配置
  24. var (
  25. EsReportIndexName string //研报ES索引
  26. SmartReportIndexName string //智能研报ES索引
  27. )
  28. // ES配置
  29. var (
  30. ES_URL string // ES服务器地址
  31. ES_USERNAME string // ES账号
  32. ES_PASSWORD string // ES密码
  33. )
  34. // BusinessCode 商家编码
  35. var BusinessCode string
  36. func init() {
  37. tmpRunMode, err := web.AppConfig.String("run_mode")
  38. if err != nil {
  39. panic("配置文件读取run_mode错误 " + err.Error())
  40. }
  41. RunMode = tmpRunMode
  42. if RunMode == "" {
  43. localIp, err := GetLocalIP()
  44. fmt.Println("localIp:", localIp)
  45. if localIp == "10.0.0.123" {
  46. RunMode = "debug"
  47. } else {
  48. RunMode = "release"
  49. }
  50. configPath := `/home/code/config/eta_hub/conf/app.conf`
  51. err = web.LoadAppConfig("ini", configPath)
  52. if err != nil {
  53. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  54. }
  55. }
  56. config, err := web.AppConfig.GetSection(RunMode)
  57. if err != nil {
  58. panic("配置文件读取错误 " + err.Error())
  59. }
  60. beeLogger.Log.Info(RunMode + " 模式")
  61. MYSQL_URL = config["mysql_url"]
  62. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  63. if RunMode == "release" {
  64. } else {
  65. }
  66. //日志配置
  67. {
  68. LogPath = config["log_path"]
  69. LogFile = config["log_file"]
  70. BinLogPath = config["binlog_path"]
  71. BinLogFile = config["binlog_file"]
  72. ApiLogPath = config["apilog_path"]
  73. ApiLogFile = config["apilog_file"]
  74. logMaxDaysStr := config["log_max_day"]
  75. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  76. }
  77. // 商家编码
  78. BusinessCode = config["business_code"]
  79. // ES 索引
  80. {
  81. EsReportIndexName = config["es_report_index_name"]
  82. SmartReportIndexName = config["es_smart_report_index_name"]
  83. }
  84. // ES配置
  85. {
  86. ES_URL = config["es_url"]
  87. ES_USERNAME = config["es_username"]
  88. ES_PASSWORD = config["es_password"]
  89. }
  90. }