config.go 5.6 KB

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