config.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package utils
  2. import (
  3. "fmt"
  4. beeLogger "github.com/beego/bee/v2/logger"
  5. "github.com/beego/beego/v2/server/web"
  6. "github.com/rdlucklib/rdluck_tools/cache"
  7. )
  8. var (
  9. RunMode string //运行模式
  10. MYSQL_URL string //数据库连接
  11. REDIS_CACHE string //缓存地址
  12. Rc *cache.Cache //redis缓存
  13. Re error //redis错误
  14. )
  15. var (
  16. STATIC_DIR string
  17. )
  18. func init() {
  19. tmpRunMode, err := web.AppConfig.String("run_mode")
  20. if err != nil {
  21. panic("配置文件读取run_mode错误 " + err.Error())
  22. }
  23. RunMode = tmpRunMode
  24. if RunMode == "" {
  25. localIp, err := GetLocalIP()
  26. fmt.Println("localIp:", localIp)
  27. if localIp == "10.0.0.123" {
  28. RunMode = "debug"
  29. } else {
  30. RunMode = "release"
  31. }
  32. fmt.Println("RunMode:", RunMode)
  33. configPath := `/home/code/config/hongze_robot/conf/app.conf`
  34. fmt.Println("configPath:", configPath)
  35. err = web.LoadAppConfig("ini", configPath)
  36. if err != nil {
  37. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  38. }
  39. }
  40. config, err := web.AppConfig.GetSection(RunMode)
  41. if err != nil {
  42. panic("配置文件读取错误 " + err.Error())
  43. }
  44. beeLogger.Log.Info(RunMode + " 模式")
  45. MYSQL_URL = config["mysql_url"]
  46. REDIS_CACHE = config["beego_cache"]
  47. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  48. if Re != nil {
  49. fmt.Println(Re)
  50. panic(Re)
  51. }
  52. if RunMode == "release" {
  53. } else {
  54. }
  55. }