config.go 949 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. config, err := web.AppConfig.GetSection(RunMode)
  25. if err != nil {
  26. panic("配置文件读取错误 " + err.Error())
  27. }
  28. beeLogger.Log.Info(RunMode + " 模式")
  29. MYSQL_URL = config["mysql_url"]
  30. REDIS_CACHE = config["beego_cache"]
  31. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  32. if Re != nil {
  33. fmt.Println(Re)
  34. panic(Re)
  35. }
  36. if RunMode == "release" {
  37. } else {
  38. }
  39. }