config.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/server/web"
  5. )
  6. var (
  7. RunMode string //运行模式
  8. MYSQL_URL string //数据库连接
  9. MYSQL_URL_ETA string
  10. )
  11. // 日志配置
  12. var (
  13. LogPath string //调用过程中的日志存放地址
  14. LogFile string
  15. BinLogPath string //数据库相关的日志存放地址
  16. BinLogFile string
  17. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  18. ApiLogFile string
  19. )
  20. // 系统配置
  21. var (
  22. DesKey string // 加密key
  23. EmailSendToUsers string // 邮件提醒人员
  24. BusinessCode string // 商户号
  25. )
  26. // 公共api内部服务调用
  27. var (
  28. // EtaPubUrl 模板消息推送
  29. EtaPubUrl string
  30. // EtaPubAuthorization 模板推送秘钥
  31. EtaPubAuthorization string
  32. // AlarmMsgUrl 报警服务地址
  33. AlarmMsgUrl string
  34. Html2ImgServerUrl string // html转图片服务地址
  35. EtaReportAppNameEn string // 内部调用该服务的英文名
  36. EtaReportKey string // 内部调用该服务的鉴权Key
  37. )
  38. func init() {
  39. tmpRunMode, err := web.AppConfig.String("run_mode")
  40. if err != nil {
  41. panic("配置文件读取run_mode错误 " + err.Error())
  42. }
  43. RunMode = tmpRunMode
  44. if RunMode == "" {
  45. localIp, err := GetLocalIP()
  46. fmt.Println("localIp:", localIp)
  47. if localIp == "10.0.0.123" {
  48. RunMode = "debug"
  49. } else {
  50. RunMode = "release"
  51. }
  52. fmt.Println("RunMode:", RunMode)
  53. configPath := `/home/code/config/eta_report/conf/app.conf`
  54. fmt.Println("configPath:", configPath)
  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. fmt.Println(RunMode + " 模式")
  65. MYSQL_URL = config["mysql_url"]
  66. MYSQL_URL_ETA = config["mysql_url_eta"]
  67. //日志配置
  68. {
  69. LogPath = config["log_path"]
  70. LogFile = config["log_file"]
  71. BinLogPath = config["binlog_path"]
  72. BinLogFile = config["binlog_file"]
  73. ApiLogPath = config["apilog_path"]
  74. ApiLogFile = config["apilog_file"]
  75. }
  76. // 系统配置
  77. {
  78. // 接口返回加密KEY
  79. DesKey = config["des_key"]
  80. // 邮件提醒人员
  81. EmailSendToUsers = config["email_send_to_users"]
  82. // 商户号
  83. BusinessCode = config["business_code"]
  84. }
  85. // 系统内部服务地址
  86. {
  87. // 发送微信模板消息地址
  88. EtaPubUrl = config["eta_pub_url"]
  89. // 发送微信模板消息地址
  90. EtaPubAuthorization = config["eta_pub_authorization"]
  91. // 报警服务地址
  92. AlarmMsgUrl = config["alarm_msg_url"]
  93. // html转图片服务地址
  94. Html2ImgServerUrl = config["html2img_server_url"]
  95. // 内部调用项目英文名
  96. EtaReportAppNameEn = config["eta_report_app_name_en"]
  97. // 内部调用鉴权Key
  98. EtaReportKey = config["eta_report_key"]
  99. }
  100. }