config.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. PYTHON_PATH string // python可执行文件地址
  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 BusinessCode string //商户号
  25. // 卓创资讯
  26. var (
  27. SCI99_COOKIE_PATH string
  28. IS_INIT_SCI99 string
  29. )
  30. // 粮油商务网
  31. var (
  32. LY_USERNAME string
  33. LY_PASSWORD string
  34. LY_JSON_PATH string
  35. LY_OPEN string
  36. )
  37. var (
  38. EDB_LIB_URL string
  39. APP_EDB_LIB_NAME_EN string
  40. EDB_LIB_Md5_KEY string
  41. )
  42. var (
  43. OLD_EXCEL_PATH_JR string
  44. )
  45. func init() {
  46. tmpRunMode, err := web.AppConfig.String("run_mode")
  47. if err != nil {
  48. panic("配置文件读取run_mode错误 " + err.Error())
  49. }
  50. RunMode = tmpRunMode
  51. if RunMode == "" {
  52. localIp, err := GetLocalIP()
  53. fmt.Println("localIp:", localIp)
  54. if localIp == "10.0.0.123" {
  55. RunMode = "debug"
  56. } else {
  57. RunMode = "release"
  58. }
  59. configPath := `/home/code/config/eta_crawler/conf/app.conf`
  60. err = web.LoadAppConfig("ini", configPath)
  61. if err != nil {
  62. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  63. }
  64. }
  65. config, err := web.AppConfig.GetSection(RunMode)
  66. if err != nil {
  67. panic("配置文件读取错误 " + err.Error())
  68. }
  69. beeLogger.Log.Info(RunMode + " 模式")
  70. // 商家编码
  71. BusinessCode = config["business_code"]
  72. EDB_LIB_URL = config["edb_lib_url"]
  73. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  74. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  75. if BusinessCode == BusinessCodeRelease {
  76. MYSQL_URL = config["mysql_url"]
  77. MYSQL_URL_DATA = config["mysql_url_data"]
  78. }
  79. if BusinessCode == BusinessCodeFuBang {
  80. SCI99_COOKIE_PATH = config["sci99_cookie_path"]
  81. IS_INIT_SCI99 = config["is_init_sci99"]
  82. EDB_LIB_URL = config["edb_lib_url"]
  83. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  84. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  85. }
  86. if BusinessCode == BusinessCodeJinRui {
  87. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  88. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  89. EDB_LIB_URL = config["edb_lib_url"]
  90. OLD_EXCEL_PATH_JR = config["old_excel_path_jr"]
  91. }
  92. if RunMode == "release" {
  93. } else {
  94. }
  95. //日志配置
  96. {
  97. LogPath = config["log_path"]
  98. LogFile = config["log_file"]
  99. BinLogPath = config["binlog_path"]
  100. BinLogFile = config["binlog_file"]
  101. ApiLogPath = config["apilog_path"]
  102. ApiLogFile = config["apilog_file"]
  103. logMaxDaysStr := config["log_max_day"]
  104. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  105. }
  106. PYTHON_PATH = config["python_path"]
  107. if PYTHON_PATH == "" {
  108. PYTHON_PATH = "python3"
  109. }
  110. {
  111. LY_USERNAME = config["ly_username"]
  112. LY_PASSWORD = config["ly_password"]
  113. LY_JSON_PATH = config["ly_json_path"]
  114. LY_OPEN = config["ly_open"]
  115. }
  116. }