config.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. ResearchReportUrl = "" //全局加密KEY
  27. )
  28. func init() {
  29. tmpRunMode, err := web.AppConfig.String("run_mode")
  30. if err != nil {
  31. panic("配置文件读取run_mode错误 " + err.Error())
  32. }
  33. RunMode = tmpRunMode
  34. fmt.Println("RunMode:", RunMode)
  35. if RunMode == "" {
  36. localIp, err := GetLocalIP()
  37. fmt.Println("localIp:", localIp)
  38. if localIp == "10.0.0.123" {
  39. RunMode = "debug"
  40. } else {
  41. RunMode = "release"
  42. }
  43. fmt.Println("RunMode:", RunMode)
  44. configPath := `/home/code/config/hongze_open_api/conf/app.conf`
  45. fmt.Println("configPath:", configPath)
  46. err = web.LoadAppConfig("ini", configPath)
  47. if err != nil {
  48. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  49. }
  50. }
  51. fmt.Println(RunMode, "模式")
  52. config, err := web.AppConfig.GetSection(RunMode)
  53. if err != nil {
  54. panic("配置文件读取错误 " + err.Error())
  55. }
  56. logs.Info(RunMode + " 模式")
  57. MYSQL_URL = config["mysql_url"]
  58. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  59. // 初始化redis
  60. REDIS_CACHE = config["beego_cache"]
  61. if len(REDIS_CACHE) <= 0 {
  62. panic("redis链接参数没有配置")
  63. }
  64. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  65. if Re != nil {
  66. fmt.Println(Re)
  67. panic(Re)
  68. }
  69. //日志类
  70. if RunMode == "release" {
  71. logDir := `/data/rdlucklog/hongze_open_api`
  72. ApiLog = log.Init("20060102.api", logDir)
  73. ResearchReportUrl = "http://8.136.199.33:8608/api/"
  74. } else {
  75. ApiLog = log.Init("20060102.api")
  76. ResearchReportUrl = "http://8.136.199.33:8608/api/"
  77. }
  78. }
  79. //http://webapi.brilliantstart.cn/api/
  80. //http://webapi.brilliantstart.cn/swagger/
  81. //http://139.196.122.219:8603/swagger/