config.go 6.1 KB

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