config.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package utils
  2. import (
  3. "fmt"
  4. beeLogger "github.com/beego/bee/v2/logger"
  5. "github.com/beego/beego/v2/server/web"
  6. )
  7. // 数据库配置
  8. var (
  9. RunMode string // 运行模式
  10. MYSQL_URL_MASTER string // 数据库地址
  11. MYSQL_URL_RDDP string // 数据库地址
  12. REDIS_CACHE string //缓存地址
  13. Rc RedisClient //redis缓存
  14. )
  15. // 阿里云配置
  16. var (
  17. Bucketname string
  18. Endpoint string
  19. Imghost string
  20. UploadDir string
  21. Upload_Audio_Dir string
  22. AccessKeyId string
  23. AccessKeySecret string
  24. )
  25. // 阿里云oss前端上传用
  26. var (
  27. AliStsScheme string
  28. RegionId string
  29. RoleArn string
  30. RoleSessionName string
  31. RAMAccessKeyId string
  32. RAMAccessKeySecret string
  33. STSTokenCacheKey string
  34. )
  35. // 基础配置
  36. var (
  37. STATIC_DIR string
  38. )
  39. var (
  40. LogPath string //调用过程中的日志存放地址
  41. LogFile string
  42. ApiLogPath string // 接口请求地址和接口返回值日志存放地址
  43. ApiLogFile string
  44. BinLogPath string // 数据库相关的日志存放地址
  45. BinLogFile string
  46. LogMaxDays int // 日志最大保留天数
  47. )
  48. var DesKey string // 接口返回加密KEY
  49. func init() {
  50. tmpRunMode, err := web.AppConfig.String("run_mode")
  51. if err != nil {
  52. panic(any("配置文件读取run_mode错误 " + err.Error()))
  53. }
  54. RunMode = tmpRunMode
  55. fmt.Println("RunMode:", RunMode)
  56. if RunMode == "" {
  57. configPath := `/home/code/config/eta_mini_crm/conf/app.conf`
  58. fmt.Println("configPath:", configPath)
  59. err = web.LoadAppConfig("ini", configPath)
  60. if err != nil {
  61. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  62. }
  63. tmpRunMode, _ := web.AppConfig.String("run_mode")
  64. RunMode = tmpRunMode
  65. }
  66. config, err := web.AppConfig.GetSection(RunMode)
  67. if err != nil {
  68. panic(any("配置文件读取错误 " + err.Error()))
  69. }
  70. beeLogger.Log.Info(RunMode + " 模式")
  71. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  72. MYSQL_URL_MASTER = config["mysql_url_master"]
  73. REDIS_CACHE = config["beego_cache"]
  74. if len(REDIS_CACHE) <= 0 {
  75. panic(any("redis链接参数没有配置"))
  76. }
  77. // 接口返回加密KEY
  78. DesKey = config["des_key"]
  79. // OSS相关
  80. {
  81. Endpoint = config["endpoint"]
  82. Bucketname = config["bucket_name"]
  83. Imghost = config["img_host"]
  84. UploadDir = config["upload_dir"]
  85. Upload_Audio_Dir = config["upload_audio_dir"]
  86. AccessKeyId = config["access_key_id"]
  87. AccessKeySecret = config["access_key_secret"]
  88. }
  89. // OSS相关(前端使用)
  90. {
  91. AliStsScheme = config["ali_sts_scheme"]
  92. RegionId = config["region_id"]
  93. RoleArn = config["role_arn"]
  94. RoleSessionName = config["role_session_name"]
  95. RAMAccessKeyId = config["ram_access_key_id"]
  96. RAMAccessKeySecret = config["ram_access_key_secret"]
  97. STSTokenCacheKey = config["sts_token_cache_key"]
  98. }
  99. // 静态文件目录
  100. STATIC_DIR = config["static_dir"]
  101. if STATIC_DIR == "" {
  102. STATIC_DIR = "./static"
  103. }
  104. // 初始化缓存
  105. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  106. if err != nil {
  107. fmt.Println("redis链接异常:", err)
  108. panic(any("redis链接参数没有配置"))
  109. }
  110. Rc = redisClient
  111. }