config.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_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. var (
  30. EDB_LIB_URL string
  31. APP_EDB_LIB_NAME_EN string
  32. EDB_LIB_Md5_KEY string
  33. )
  34. func init() {
  35. tmpRunMode, err := web.AppConfig.String("run_mode")
  36. if err != nil {
  37. panic("配置文件读取run_mode错误 " + err.Error())
  38. }
  39. RunMode = tmpRunMode
  40. if RunMode == "" {
  41. localIp, err := GetLocalIP()
  42. fmt.Println("localIp:", localIp)
  43. if localIp == "10.0.0.123" {
  44. RunMode = "debug"
  45. } else {
  46. RunMode = "release"
  47. }
  48. configPath := `/home/code/config/eta_crawler/conf/app.conf`
  49. err = web.LoadAppConfig("ini", configPath)
  50. if err != nil {
  51. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  52. }
  53. }
  54. config, err := web.AppConfig.GetSection(RunMode)
  55. if err != nil {
  56. panic("配置文件读取错误 " + err.Error())
  57. }
  58. beeLogger.Log.Info(RunMode + " 模式")
  59. // 商家编码
  60. BusinessCode = config["business_code"]
  61. if BusinessCode == BusinessCodeRelease {
  62. MYSQL_URL = config["mysql_url"]
  63. MYSQL_URL_DATA = config["mysql_url_data"]
  64. }
  65. if BusinessCode == BusinessCodeFuBang {
  66. SCI99_COOKIE_PATH = config["sci99_cookie_path"]
  67. IS_INIT_SCI99 = config["is_init_sci99"]
  68. EDB_LIB_URL = config["edb_lib_url"]
  69. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  70. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  71. }
  72. if RunMode == "release" {
  73. } else {
  74. }
  75. //日志配置
  76. {
  77. LogPath = config["log_path"]
  78. LogFile = config["log_file"]
  79. BinLogPath = config["binlog_path"]
  80. BinLogFile = config["binlog_file"]
  81. ApiLogPath = config["apilog_path"]
  82. ApiLogFile = config["apilog_file"]
  83. logMaxDaysStr := config["log_max_day"]
  84. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  85. }
  86. }