config.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. func init() {
  24. tmpRunMode, err := web.AppConfig.String("run_mode")
  25. if err != nil {
  26. panic("配置文件读取run_mode错误 " + err.Error())
  27. }
  28. RunMode = tmpRunMode
  29. if RunMode == "" {
  30. localIp, err := GetLocalIP()
  31. fmt.Println("localIp:", localIp)
  32. if localIp == "10.0.0.123" {
  33. RunMode = "debug"
  34. } else {
  35. RunMode = "release"
  36. }
  37. configPath := `/home/code/config/eta_crawler/conf/app.conf`
  38. err = web.LoadAppConfig("ini", configPath)
  39. if err != nil {
  40. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  41. }
  42. }
  43. config, err := web.AppConfig.GetSection(RunMode)
  44. if err != nil {
  45. panic("配置文件读取错误 " + err.Error())
  46. }
  47. beeLogger.Log.Info(RunMode + " 模式")
  48. MYSQL_URL = config["mysql_url"]
  49. MYSQL_URL_DATA = config["mysql_url_data"]
  50. if RunMode == "release" {
  51. } else {
  52. }
  53. //日志配置
  54. {
  55. LogPath = config["log_path"]
  56. LogFile = config["log_file"]
  57. BinLogPath = config["binlog_path"]
  58. BinLogFile = config["binlog_file"]
  59. ApiLogPath = config["apilog_path"]
  60. ApiLogFile = config["apilog_file"]
  61. logMaxDaysStr := config["log_max_day"]
  62. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  63. }
  64. }