config.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/core/logs"
  5. "github.com/beego/beego/v2/server/web"
  6. "rdluck_tools/cache"
  7. "rdluck_tools/log"
  8. )
  9. var (
  10. RunMode string //运行模式
  11. MYSQL_URL string //数据库连接
  12. MYSQL_URL_RDDP string //数据库连接
  13. REDIS_CACHE string //缓存地址
  14. Rc *cache.Cache //redis缓存
  15. Re error //redis错误
  16. )
  17. var ApiLog *log.Log
  18. var (
  19. Bucketname string = "hongze"
  20. Endpoint string
  21. Imghost string = "https://hongze.oss-accelerate.aliyuncs.com/"
  22. Upload_dir string = "static/images/"
  23. Upload_Audio_Dir string = "static/audio/"
  24. AccessKeyId string = "LTAIFMZYQhS2BTvW"
  25. AccessKeySecret string = "12kk1ptCHoGWedhBnKRVW5hRJzq9Fq"
  26. )
  27. func init() {
  28. tmpRunMode, err := web.AppConfig.String("run_mode")
  29. if err != nil {
  30. panic("配置文件读取run_mode错误 " + err.Error())
  31. }
  32. RunMode = tmpRunMode
  33. fmt.Println(RunMode, "模式")
  34. config, err := web.AppConfig.GetSection(RunMode)
  35. if err != nil {
  36. panic("配置文件读取错误 " + err.Error())
  37. }
  38. logs.Info(RunMode + " 模式")
  39. MYSQL_URL = config["mysql_url"]
  40. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  41. // 初始化redis
  42. REDIS_CACHE = config["beego_cache"]
  43. if len(REDIS_CACHE) <= 0 {
  44. panic("redis链接参数没有配置")
  45. }
  46. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  47. if Re != nil {
  48. fmt.Println(Re)
  49. panic(Re)
  50. }
  51. //日志类
  52. if RunMode == "release" {
  53. logDir := `/data/rdlucklog/hongze_open_api`
  54. ApiLog = log.Init("20060102.api", logDir)
  55. } else {
  56. ApiLog = log.Init("20060102.api")
  57. }
  58. }
  59. //http://webapi.brilliantstart.cn/api/
  60. //http://webapi.brilliantstart.cn/swagger/
  61. //http://139.196.122.219:8603/swagger/