config.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. var ObjectStorageClient string // 目前有oss minio,默认oss
  16. // 阿里云配置
  17. var (
  18. Bucketname string
  19. Endpoint string
  20. Imghost string
  21. UploadDir string
  22. Upload_Audio_Dir string
  23. AccessKeyId string
  24. AccessKeySecret string
  25. )
  26. // MinIo配置
  27. var (
  28. MinIoBucketname string
  29. MinIoEndpoint string
  30. MinIoBackEndpoint string
  31. MinIoPdfhost string
  32. MinIoUploadDir string
  33. MinIoAccessKeyId string
  34. MinIoAccessKeySecret string
  35. MinIoUseSSL string
  36. MinIoPort string
  37. MinIoRegion string
  38. )
  39. // 阿里云oss前端上传用
  40. var (
  41. AliStsScheme string
  42. RegionId string
  43. RoleArn string
  44. RoleSessionName string
  45. RAMAccessKeyId string
  46. RAMAccessKeySecret string
  47. STSTokenCacheKey string
  48. )
  49. // 基础配置
  50. var (
  51. STATIC_DIR string
  52. RESOURCE_DIR string
  53. UPLOAD_PDF_SIZE string // 单位MB
  54. )
  55. // ES配置
  56. var (
  57. ES_URL string // ES服务器地址
  58. ES_USERNAME string // ES账号
  59. ES_PASSWORD string // ES密码
  60. )
  61. // ES索引配置
  62. var (
  63. MINI_REPORT_INDEX_NAME string // 小程序的pdf报告索引
  64. )
  65. var (
  66. LogPath string //调用过程中的日志存放地址
  67. LogFile string
  68. ApiLogPath string // 接口请求地址和接口返回值日志存放地址
  69. ApiLogFile string
  70. BinLogPath string // 数据库相关的日志存放地址
  71. BinLogFile string
  72. LogMaxDays int // 日志最大保留天数
  73. )
  74. var DesKey string // 接口返回加密KEY
  75. func init() {
  76. tmpRunMode, err := web.AppConfig.String("run_mode")
  77. if err != nil {
  78. panic(any("配置文件读取run_mode错误 " + err.Error()))
  79. }
  80. RunMode = tmpRunMode
  81. fmt.Println("RunMode:", RunMode)
  82. if RunMode == "" {
  83. configPath := `/home/code/config/eta_mini_crm/conf/app.conf`
  84. fmt.Println("configPath:", configPath)
  85. err = web.LoadAppConfig("ini", configPath)
  86. if err != nil {
  87. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  88. }
  89. tmpRunMode, _ := web.AppConfig.String("run_mode")
  90. RunMode = tmpRunMode
  91. }
  92. config, err := web.AppConfig.GetSection(RunMode)
  93. if err != nil {
  94. panic(any("配置文件读取错误 " + err.Error()))
  95. }
  96. beeLogger.Log.Info(RunMode + " 模式")
  97. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  98. MYSQL_URL_MASTER = config["mysql_url_master"]
  99. REDIS_CACHE = config["beego_cache"]
  100. if len(REDIS_CACHE) <= 0 {
  101. panic(any("redis链接参数没有配置"))
  102. }
  103. // 接口返回加密KEY
  104. DesKey = config["des_key"]
  105. // 对象存储客户端
  106. ObjectStorageClient = config["object_storage_client"]
  107. if ObjectStorageClient == "" {
  108. ObjectStorageClient = "oss"
  109. }
  110. // OSS相关
  111. {
  112. Endpoint = config["endpoint"]
  113. Bucketname = config["bucket_name"]
  114. Imghost = config["img_host"]
  115. UploadDir = config["upload_dir"]
  116. Upload_Audio_Dir = config["upload_audio_dir"]
  117. AccessKeyId = config["access_key_id"]
  118. AccessKeySecret = config["access_key_secret"]
  119. }
  120. // MinIo相关
  121. {
  122. MinIoEndpoint = config["minio_endpoint"]
  123. MinIoBackEndpoint = config["minio_back_endpoint"]
  124. MinIoBucketname = config["minio_bucket_name"]
  125. MinIoPdfhost = config["minio_pdf_host"]
  126. MinIoUploadDir = config["minio_upload_dir"]
  127. MinIoAccessKeyId = config["minio_access_key_id"]
  128. MinIoAccessKeySecret = config["minio_access_key_secret"]
  129. MinIoUseSSL = config["minio_use_ssl"]
  130. MinIoPort = config["minio_port"]
  131. MinIoRegion = config["minio_region"]
  132. }
  133. // OSS相关(前端使用)
  134. {
  135. AliStsScheme = config["ali_sts_scheme"]
  136. RegionId = config["region_id"]
  137. RoleArn = config["role_arn"]
  138. RoleSessionName = config["role_session_name"]
  139. RAMAccessKeyId = config["ram_access_key_id"]
  140. RAMAccessKeySecret = config["ram_access_key_secret"]
  141. STSTokenCacheKey = config["sts_token_cache_key"]
  142. }
  143. // ES配置
  144. {
  145. ES_URL = config["es_url"]
  146. ES_USERNAME = config["es_username"]
  147. ES_PASSWORD = config["es_password"]
  148. }
  149. // ES 索引
  150. {
  151. MINI_REPORT_INDEX_NAME = config["mini_report_index_name"]
  152. }
  153. // 初始化ES
  154. initEs()
  155. // 静态文件目录
  156. STATIC_DIR = config["static_dir"]
  157. if STATIC_DIR == "" {
  158. STATIC_DIR = "./static"
  159. }
  160. RESOURCE_DIR = config["resource_dir"]
  161. if RESOURCE_DIR == "" {
  162. RESOURCE_DIR = "dongwu/"
  163. }
  164. UPLOAD_PDF_SIZE = config["upload_pdf_size"]
  165. if UPLOAD_PDF_SIZE == "" {
  166. UPLOAD_PDF_SIZE = "15"
  167. }
  168. // 初始化缓存
  169. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  170. if err != nil {
  171. fmt.Println("redis链接异常:", err)
  172. panic(any("redis链接参数没有配置"))
  173. }
  174. Rc = redisClient
  175. }