config.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. // 中国煤炭网
  46. var (
  47. CoalFilePath string // excel文件地址
  48. CoalOpen string // 是否配置中国煤炭网数据源,1已配置
  49. CoalMailAttachmentOpen string // 获取邮件附件功能,1已配置
  50. CoalMailAttachmentTime string // 获取邮件附件功能时间
  51. CoalEmailAddress string // 中国煤炭网监听邮箱服务器地址
  52. CoalEmailUseName string // 中国煤炭网监听邮箱用户名
  53. CoalEmailPassword string // 中国煤炭网监听邮箱密码
  54. CoalEmailFolder string // 中国煤炭网监听邮箱文件夹
  55. CoalEmailReadBatch string // 中国煤炭网监听邮箱读取批次
  56. CoalEmailFileExt string // 中国煤炭网监听文件后缀
  57. CoalEmailNDay string // 中国煤炭网监听取最近N天数据
  58. )
  59. func init() {
  60. tmpRunMode, err := web.AppConfig.String("run_mode")
  61. if err != nil {
  62. panic("配置文件读取run_mode错误 " + err.Error())
  63. }
  64. RunMode = tmpRunMode
  65. if RunMode == "" {
  66. localIp, err := GetLocalIP()
  67. fmt.Println("localIp:", localIp)
  68. if localIp == "10.0.0.123" {
  69. RunMode = "debug"
  70. } else {
  71. RunMode = "release"
  72. }
  73. configPath := `/home/code/config/eta_crawler/conf/app.conf`
  74. err = web.LoadAppConfig("ini", configPath)
  75. if err != nil {
  76. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  77. }
  78. }
  79. config, err := web.AppConfig.GetSection(RunMode)
  80. if err != nil {
  81. panic("配置文件读取错误 " + err.Error())
  82. }
  83. beeLogger.Log.Info(RunMode + " 模式")
  84. // 商家编码
  85. BusinessCode = config["business_code"]
  86. EDB_LIB_URL = config["edb_lib_url"]
  87. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  88. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  89. if BusinessCode == BusinessCodeRelease {
  90. MYSQL_URL = config["mysql_url"]
  91. MYSQL_URL_DATA = config["mysql_url_data"]
  92. }
  93. if BusinessCode == BusinessCodeFuBang {
  94. SCI99_COOKIE_PATH = config["sci99_cookie_path"]
  95. IS_INIT_SCI99 = config["is_init_sci99"]
  96. EDB_LIB_URL = config["edb_lib_url"]
  97. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  98. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  99. }
  100. if BusinessCode == BusinessCodeJinRui {
  101. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  102. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  103. EDB_LIB_URL = config["edb_lib_url"]
  104. OLD_EXCEL_PATH_JR = config["old_excel_path_jr"]
  105. }
  106. if RunMode == "release" {
  107. } else {
  108. }
  109. //日志配置
  110. {
  111. LogPath = config["log_path"]
  112. LogFile = config["log_file"]
  113. BinLogPath = config["binlog_path"]
  114. BinLogFile = config["binlog_file"]
  115. ApiLogPath = config["apilog_path"]
  116. ApiLogFile = config["apilog_file"]
  117. logMaxDaysStr := config["log_max_day"]
  118. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  119. }
  120. PYTHON_PATH = config["python_path"]
  121. if PYTHON_PATH == "" {
  122. PYTHON_PATH = "python3"
  123. }
  124. {
  125. LY_USERNAME = config["ly_username"]
  126. LY_PASSWORD = config["ly_password"]
  127. LY_JSON_PATH = config["ly_json_path"]
  128. LY_OPEN = config["ly_open"]
  129. }
  130. // 中国煤炭网
  131. {
  132. CoalFilePath = config["coal_file_path"]
  133. CoalOpen = config["coal_open"]
  134. CoalMailAttachmentOpen = config["coal_mail_attachment_open"]
  135. CoalMailAttachmentTime = config["coal_mail_attachment_time"]
  136. CoalEmailAddress = config["coal_email_address"]
  137. CoalEmailUseName = config["coal_email_use_name"]
  138. CoalEmailPassword = config["coal_email_password"]
  139. CoalEmailFolder = config["coal_email_folder"]
  140. CoalEmailReadBatch = config["coal_email_read_batch"]
  141. CoalEmailFileExt = config["coal_email_file_ext"]
  142. CoalEmailNDay = config["coal_email_n_day"]
  143. }
  144. }