config.go 4.6 KB

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