config.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/server/web"
  5. )
  6. var (
  7. RunMode string //运行模式
  8. MYSQL_URL string //数据库连接
  9. MYSQL_URL_ETA string
  10. )
  11. // 日志配置
  12. var (
  13. LogPath string //调用过程中的日志存放地址
  14. LogFile string
  15. BinLogPath string //数据库相关的日志存放地址
  16. BinLogFile string
  17. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  18. ApiLogFile string
  19. )
  20. func init() {
  21. tmpRunMode, err := web.AppConfig.String("run_mode")
  22. if err != nil {
  23. panic("配置文件读取run_mode错误 " + err.Error())
  24. }
  25. RunMode = tmpRunMode
  26. if RunMode == "" {
  27. localIp, err := GetLocalIP()
  28. fmt.Println("localIp:", localIp)
  29. if localIp == "10.0.0.123" {
  30. RunMode = "debug"
  31. } else {
  32. RunMode = "release"
  33. }
  34. fmt.Println("RunMode:", RunMode)
  35. configPath := `/home/code/config/eta_report/conf/app.conf`
  36. fmt.Println("configPath:", configPath)
  37. err = web.LoadAppConfig("ini", configPath)
  38. if err != nil {
  39. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  40. }
  41. }
  42. config, err := web.AppConfig.GetSection(RunMode)
  43. if err != nil {
  44. panic("配置文件读取错误 " + err.Error())
  45. }
  46. fmt.Println(RunMode + " 模式")
  47. MYSQL_URL = config["mysql_url"]
  48. MYSQL_URL_ETA = config["mysql_url_eta"]
  49. if RunMode == "release" {
  50. } else {
  51. }
  52. //日志配置
  53. {
  54. LogPath = config["log_path"]
  55. LogFile = config["log_file"]
  56. BinLogPath = config["binlog_path"]
  57. BinLogFile = config["binlog_file"]
  58. ApiLogPath = config["apilog_path"]
  59. ApiLogFile = config["apilog_file"]
  60. }
  61. }