config.go 5.4 KB

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