config.go 2.6 KB

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