config.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. PRCPool ClientPool //rpc连接池
  15. MinioClient *MinioOss
  16. )
  17. var ObjectStorageClient string // 目前有oss minio,默认oss
  18. // 推送模版消息
  19. var (
  20. ETA_PUB_URL string
  21. ETA_PUB_TOKEN string
  22. )
  23. // 阿里云配置
  24. var (
  25. Bucketname string
  26. Endpoint string
  27. Imghost string
  28. UploadDir string
  29. AccessKeyId string
  30. AccessKeySecret string
  31. )
  32. // MinIo配置
  33. var (
  34. MinIoBucketname string
  35. MinIoEndpoint string
  36. MinIoBackEndpoint string
  37. MinIoPdfhost string
  38. MinIoUploadDir string
  39. MinIoAccessKeyId string
  40. MinIoAccessKeySecret string
  41. MinIoUseSSL string
  42. MinIoPort string
  43. MinIoRegion string
  44. )
  45. // 阿里云oss前端上传用
  46. var (
  47. AliStsScheme string
  48. RegionId string
  49. RoleArn string
  50. RoleSessionName string
  51. RAMAccessKeyId string
  52. RAMAccessKeySecret string
  53. STSTokenCacheKey string
  54. )
  55. // 基础配置
  56. var (
  57. STATIC_DIR string
  58. RESOURCE_DIR string
  59. UPLOAD_PDF_SIZE string // 单位MB
  60. UPLOAD_IMG_SIZE string
  61. UPLOAD_AUDIO_SIZE string
  62. UPLOAD_VIDEO_SIZE string
  63. UPLOAD_MULTI_VIDEO_SIZE string
  64. )
  65. // ES配置
  66. var (
  67. ES_URL string // ES服务器地址
  68. ES_USERNAME string // ES账号
  69. ES_PASSWORD string // ES密码
  70. MEDIA_INDEX string
  71. )
  72. var (
  73. HT_WX_APP_SECRET string
  74. HT_WX_APPID string
  75. HT_MINI_APPID string
  76. TEMPLATE_ID_BY_PRODUCT string
  77. RESOURCE string
  78. )
  79. var (
  80. ENABLE_TASK string
  81. )
  82. // ES索引配置
  83. var (
  84. MINI_REPORT_INDEX_NAME string // 小程序的pdf报告索引
  85. )
  86. var (
  87. LogPath string //调用过程中的日志存放地址
  88. LogFile string
  89. ApiLogPath string // 接口请求地址和接口返回值日志存放地址
  90. ApiLogFile string
  91. BinLogPath string // 数据库相关的日志存放地址
  92. BinLogFile string
  93. LogMaxDays int // 日志最大保留天数
  94. )
  95. // SSO登录
  96. var (
  97. SSO_URL string
  98. )
  99. var DesKey string // 接口返回加密KEY
  100. func init() {
  101. tmpRunMode, err := web.AppConfig.String("run_mode")
  102. if err != nil {
  103. panic(any("配置文件读取run_mode错误 " + err.Error()))
  104. }
  105. RunMode = tmpRunMode
  106. fmt.Println("RunMode:", RunMode)
  107. if RunMode == "" {
  108. configPath := `/home/code/config/eta_mini_crm_ht/conf/app.conf`
  109. fmt.Println("configPath:", configPath)
  110. err = web.LoadAppConfig("ini", configPath)
  111. if err != nil {
  112. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  113. }
  114. tmpRunMode, _ := web.AppConfig.String("run_mode")
  115. RunMode = tmpRunMode
  116. }
  117. config, err := web.AppConfig.GetSection(RunMode)
  118. if err != nil {
  119. panic(any("配置文件读取错误 " + err.Error()))
  120. }
  121. beeLogger.Log.Info(RunMode + " 模式")
  122. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  123. MYSQL_URL_MASTER = config["mysql_url_master"]
  124. REDIS_CACHE = config["beego_cache"]
  125. if len(REDIS_CACHE) <= 0 {
  126. panic(any("redis链接参数没有配置"))
  127. }
  128. // 接口返回加密KEY
  129. DesKey = config["des_key"]
  130. // 对象存储客户端
  131. ObjectStorageClient = config["object_storage_client"]
  132. if ObjectStorageClient == "" {
  133. ObjectStorageClient = "oss"
  134. }
  135. // OSS相关
  136. {
  137. Endpoint = config["endpoint"]
  138. Bucketname = config["bucket_name"]
  139. Imghost = config["img_host"]
  140. UploadDir = config["upload_dir"]
  141. AccessKeyId = config["access_key_id"]
  142. AccessKeySecret = config["access_key_secret"]
  143. }
  144. // MinIo相关
  145. {
  146. MinIoEndpoint = config["minio_endpoint"]
  147. MinIoBackEndpoint = config["minio_back_endpoint"]
  148. MinIoBucketname = config["minio_bucket_name"]
  149. MinIoPdfhost = config["minio_pdf_host"]
  150. MinIoUploadDir = config["minio_upload_dir"]
  151. MinIoAccessKeyId = config["minio_access_key_id"]
  152. MinIoAccessKeySecret = config["minio_access_key_secret"]
  153. MinIoUseSSL = config["minio_use_ssl"]
  154. MinIoPort = config["minio_port"]
  155. MinIoRegion = config["minio_region"]
  156. }
  157. // OSS相关(前端使用)
  158. {
  159. AliStsScheme = config["ali_sts_scheme"]
  160. RegionId = config["region_id"]
  161. RoleArn = config["role_arn"]
  162. RoleSessionName = config["role_session_name"]
  163. RAMAccessKeyId = config["ram_access_key_id"]
  164. RAMAccessKeySecret = config["ram_access_key_secret"]
  165. STSTokenCacheKey = config["sts_token_cache_key"]
  166. }
  167. //推送模版消息
  168. {
  169. ETA_PUB_URL = config["eta_pub_url"]
  170. ETA_PUB_TOKEN = config["eta_pub_authorization"]
  171. }
  172. // ES配置
  173. {
  174. ES_URL = config["es_url"]
  175. ES_USERNAME = config["es_username"]
  176. ES_PASSWORD = config["es_password"]
  177. }
  178. {
  179. ENABLE_TASK = config["enable_task"]
  180. }
  181. // ES 索引
  182. {
  183. MINI_REPORT_INDEX_NAME = config["mini_report_index_name"]
  184. MEDIA_INDEX = config["media_index"]
  185. }
  186. {
  187. HT_WX_APPID = config["ht_wx_appid"]
  188. HT_WX_APP_SECRET = config["ht_wx_app_secret"]
  189. TEMPLATE_ID_BY_PRODUCT = config["template_id_by_product"]
  190. HT_MINI_APPID = config["ht_mini_appid"]
  191. RESOURCE = config["resource"]
  192. }
  193. {
  194. SSO_URL = config["sso_url"]
  195. }
  196. // 初始化ES
  197. initEs()
  198. // 静态文件目录
  199. STATIC_DIR = config["static_dir"]
  200. if STATIC_DIR == "" {
  201. STATIC_DIR = "./static"
  202. }
  203. RESOURCE_DIR = config["resource_dir"]
  204. if RESOURCE_DIR == "" {
  205. RESOURCE_DIR = "ht/"
  206. }
  207. UPLOAD_PDF_SIZE = config["upload_pdf_size"]
  208. if UPLOAD_PDF_SIZE == "" {
  209. UPLOAD_PDF_SIZE = "15"
  210. }
  211. UPLOAD_IMG_SIZE = config["upload_img_size"]
  212. if UPLOAD_IMG_SIZE == "" {
  213. UPLOAD_IMG_SIZE = "200"
  214. }
  215. UPLOAD_AUDIO_SIZE = config["upload_audio_size"]
  216. if UPLOAD_AUDIO_SIZE == "" {
  217. UPLOAD_AUDIO_SIZE = "100"
  218. }
  219. UPLOAD_VIDEO_SIZE = config["upload_video_size"]
  220. if UPLOAD_VIDEO_SIZE == "" {
  221. UPLOAD_VIDEO_SIZE = "1000"
  222. }
  223. UPLOAD_MULTI_VIDEO_SIZE = config["upload_multi_video_size"]
  224. if UPLOAD_MULTI_VIDEO_SIZE == "" {
  225. UPLOAD_MULTI_VIDEO_SIZE = "1"
  226. }
  227. // 初始化缓存
  228. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  229. if err != nil {
  230. fmt.Println("redis链接异常:", err)
  231. panic(any("redis链接参数没有配置"))
  232. }
  233. Rc = redisClient
  234. MinioClient = DefaultClient()
  235. }