config.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package utils
  2. import (
  3. "fmt"
  4. "strconv"
  5. beeLogger "github.com/beego/bee/v2/logger"
  6. "github.com/beego/beego/v2/server/web"
  7. )
  8. var (
  9. RunMode string //运行模式
  10. MYSQL_URL string //数据库连接
  11. MYSQL_URL_DATA 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. var BusinessCode string //商户号
  24. // 卓创资讯
  25. var (
  26. SCI99_COOKIE_PATH string
  27. IS_INIT_SCI99 string
  28. )
  29. // 粮油商务网
  30. var (
  31. LY_USERNAME string
  32. LY_PASSWORD string
  33. LY_JSON_PATH string
  34. )
  35. var (
  36. EDB_LIB_URL string
  37. APP_EDB_LIB_NAME_EN string
  38. EDB_LIB_Md5_KEY string
  39. )
  40. var (
  41. OLD_EXCEL_PATH_JR 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. fmt.Println("localIp:", localIp)
  52. if localIp == "10.0.0.123" {
  53. RunMode = "debug"
  54. } else {
  55. RunMode = "release"
  56. }
  57. configPath := `/home/code/config/eta_crawler/conf/app.conf`
  58. err = web.LoadAppConfig("ini", configPath)
  59. if err != nil {
  60. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  61. }
  62. }
  63. config, err := web.AppConfig.GetSection(RunMode)
  64. if err != nil {
  65. panic("配置文件读取错误 " + err.Error())
  66. }
  67. beeLogger.Log.Info(RunMode + " 模式")
  68. // 商家编码
  69. BusinessCode = config["business_code"]
  70. if BusinessCode == BusinessCodeRelease {
  71. MYSQL_URL = config["mysql_url"]
  72. MYSQL_URL_DATA = config["mysql_url_data"]
  73. }
  74. if BusinessCode == BusinessCodeFuBang {
  75. SCI99_COOKIE_PATH = config["sci99_cookie_path"]
  76. IS_INIT_SCI99 = config["is_init_sci99"]
  77. EDB_LIB_URL = config["edb_lib_url"]
  78. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  79. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  80. }
  81. if BusinessCode == BusinessCodeJinRui {
  82. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  83. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  84. EDB_LIB_URL = config["edb_lib_url"]
  85. OLD_EXCEL_PATH_JR = config["old_excel_path_jr"]
  86. }
  87. if RunMode == "release" {
  88. } else {
  89. // todo 粮油商务网 上线再根据环境做配置
  90. LY_USERNAME = config["ly_username"]
  91. LY_PASSWORD = config["ly_password"]
  92. LY_JSON_PATH = config["ly_json_path"]
  93. }
  94. //日志配置
  95. {
  96. LogPath = config["log_path"]
  97. LogFile = config["log_file"]
  98. BinLogPath = config["binlog_path"]
  99. BinLogFile = config["binlog_file"]
  100. ApiLogPath = config["apilog_path"]
  101. ApiLogFile = config["apilog_file"]
  102. logMaxDaysStr := config["log_max_day"]
  103. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  104. }
  105. }