config.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. package utils
  2. import (
  3. "fmt"
  4. beeLogger "github.com/beego/bee/v2/logger"
  5. "github.com/beego/beego/v2/server/web"
  6. "github.com/qiniu/qmgo"
  7. "strconv"
  8. )
  9. var (
  10. RunMode string //运行模式
  11. MYSQL_URL string //数据库连接
  12. MYSQL_URL_DATA string
  13. MYSQL_URL_RDDP string
  14. MgoUrlData string // mongodb数据库连接配置
  15. REDIS_CACHE string //缓存地址
  16. //Rc *cache.Cache //redis缓存
  17. Re error //redis错误
  18. Rc RedisClient //redis缓存
  19. MgoDataCli *qmgo.Client // mongodb客户端连接
  20. MgoDataDbName string // mongodb指标数据的库名
  21. )
  22. // 日志配置
  23. var (
  24. LogPath string //调用过程中的日志存放地址
  25. LogFile string
  26. BinLogPath string //数据库相关的日志存放地址
  27. BinLogFile string
  28. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  29. ApiLogFile string
  30. LogMaxDays int //日志最大保留天数
  31. )
  32. var (
  33. BusinessCode string //商家编码
  34. AppId string
  35. Secret string
  36. )
  37. // ES索引配置
  38. var (
  39. EsReportIndexName string //研报ES索引
  40. EsEnglishReportIndexName string //英文研报ES索引
  41. SmartReportIndexName string //智能研报ES索引
  42. )
  43. // ES配置
  44. var (
  45. ES_URL string // ES服务器地址
  46. ES_USERNAME string // ES账号
  47. ES_PASSWORD string // ES密码
  48. )
  49. // 内部配置
  50. var (
  51. EdbChartLibUrl string // 图库服务地址
  52. // EDB_LIB_URL 公共指标库
  53. EDB_LIB_URL string
  54. APP_EDB_LIB_NAME_EN string
  55. EDB_LIB_Md5_KEY string
  56. )
  57. var (
  58. UseMongo bool // 是否使用mongo
  59. )
  60. // 基础配置
  61. var (
  62. STATIC_DIR string
  63. ResourceProxyUrl string // 代理资源地址
  64. )
  65. // 对象存储客户端
  66. var (
  67. ObjectStorageClient string
  68. )
  69. // MinIo配置
  70. var (
  71. MinIoBucketname string
  72. MinIoEndpoint string
  73. MinIoBackEndpoint string
  74. MinIoImghost string
  75. MinIoUploadDir string
  76. MinIoUpload_Audio_Dir string
  77. MinIoAccessKeyId string
  78. MinIoAccessKeySecret string
  79. MinIoUseSSL string
  80. MinIoPort string
  81. MinIoRegion string
  82. )
  83. // 阿里云oss前端上传用
  84. var (
  85. AliStsScheme string
  86. RegionId string
  87. RoleArn string
  88. RoleSessionName string
  89. RAMAccessKeyId string
  90. RAMAccessKeySecret string
  91. STSTokenCacheKey string
  92. )
  93. // 阿里云配置
  94. var (
  95. Bucketname string
  96. Endpoint string
  97. Imghost string
  98. UploadDir string
  99. Upload_Audio_Dir string
  100. AccessKeyId string
  101. AccessKeySecret string
  102. )
  103. // S3配置
  104. var (
  105. S3Endpoint string
  106. S3BackEndpoint string
  107. S3BucketName string
  108. S3UploadDir string
  109. S3AccessKeyId string
  110. S3AccessKeySecret string
  111. S3Host string
  112. S3Region string
  113. S3ForceStyle string
  114. S3EndpointPort string
  115. S3Protocol string
  116. S3DisableSSL string
  117. S3OpenAcl string
  118. )
  119. func init() {
  120. tmpRunMode, err := web.AppConfig.String("run_mode")
  121. if err != nil {
  122. panic("配置文件读取run_mode错误 " + err.Error())
  123. }
  124. RunMode = tmpRunMode
  125. if RunMode == "" {
  126. localIp, err := GetLocalIP()
  127. fmt.Println("localIp:", localIp)
  128. if localIp == "10.0.0.123" {
  129. RunMode = "debug"
  130. } else {
  131. RunMode = "release"
  132. }
  133. configPath := `/home/code/config/eta_hub/conf/app.conf`
  134. err = web.LoadAppConfig("ini", configPath)
  135. if err != nil {
  136. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  137. }
  138. }
  139. config, err := web.AppConfig.GetSection(RunMode)
  140. if err != nil {
  141. panic("配置文件读取错误 " + err.Error())
  142. }
  143. beeLogger.Log.Info(RunMode + " 模式")
  144. MYSQL_URL = config["mysql_url"]
  145. MYSQL_URL_DATA = config["mysql_url_data"]
  146. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  147. // mongodb数据库连接配置
  148. MgoUrlData = config["mgo_url_data"]
  149. //REDIS_CACHE = config["beego_cache"]
  150. //if len(REDIS_CACHE) <= 0 {
  151. // panic(any("redis链接参数没有配置"))
  152. //}
  153. // 初始化缓存
  154. //redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  155. //if err != nil {
  156. // fmt.Println("redis链接异常:", err)
  157. // panic(any(Re))
  158. //}
  159. //
  160. //Rc = redisClient
  161. //商家编码
  162. BusinessCode = config["business_code"]
  163. if BusinessCode == "" {
  164. panic("商家编码未配置,请先配置商家编码")
  165. }
  166. AppId = config["appid"]
  167. if AppId == "" {
  168. panic("appid未配置")
  169. }
  170. Secret = config["secret"]
  171. if Secret == "" {
  172. panic("secret未配置")
  173. }
  174. //日志配置
  175. {
  176. LogPath = config["log_path"]
  177. LogFile = config["log_file"]
  178. BinLogPath = config["binlog_path"]
  179. BinLogFile = config["binlog_file"]
  180. ApiLogPath = config["apilog_path"]
  181. ApiLogFile = config["apilog_file"]
  182. logMaxDaysStr := config["log_max_day"]
  183. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  184. }
  185. // ES 索引
  186. {
  187. EsReportIndexName = config["es_report_index_name"]
  188. EsEnglishReportIndexName = config["es_english_report_index_name"]
  189. SmartReportIndexName = config["es_smart_report_index_name"]
  190. }
  191. // ES配置
  192. {
  193. ES_URL = config["es_url"]
  194. ES_USERNAME = config["es_username"]
  195. ES_PASSWORD = config["es_password"]
  196. }
  197. // 内部配置
  198. {
  199. EdbChartLibUrl = config["edb_chart_lib_url"]
  200. // 公共指标库相关
  201. EDB_LIB_URL = config["edb_lib_url"]
  202. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  203. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  204. }
  205. // 基础配置
  206. {
  207. STATIC_DIR = config["static_dir"]
  208. // 代理资源地址
  209. ResourceProxyUrl = config["resource_proxy_url"]
  210. }
  211. // 对象存储客户端
  212. ObjectStorageClient = config["object_storage_client"]
  213. // MinIo相关
  214. {
  215. MinIoEndpoint = config["minio_endpoint"]
  216. MinIoBackEndpoint = config["minio_back_endpoint"]
  217. MinIoBucketname = config["minio_bucket_name"]
  218. MinIoImghost = config["minio_img_host"]
  219. MinIoUploadDir = config["minio_upload_dir"]
  220. MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
  221. MinIoAccessKeyId = config["minio_access_key_id"]
  222. MinIoAccessKeySecret = config["minio_access_key_secret"]
  223. MinIoUseSSL = config["minio_use_ssl"]
  224. MinIoPort = config["minio_port"]
  225. MinIoRegion = config["minio_region"]
  226. }
  227. // OSS相关(前端使用)
  228. {
  229. AliStsScheme = config["ali_sts_scheme"]
  230. RegionId = config["region_id"]
  231. RoleArn = config["role_arn"]
  232. RoleSessionName = config["role_session_name"]
  233. RAMAccessKeyId = config["ram_access_key_id"]
  234. RAMAccessKeySecret = config["ram_access_key_secret"]
  235. STSTokenCacheKey = config["sts_token_cache_key"]
  236. }
  237. // OSS相关
  238. {
  239. Endpoint = config["endpoint"]
  240. Bucketname = config["bucket_name"]
  241. Imghost = config["img_host"]
  242. UploadDir = config["upload_dir"]
  243. Upload_Audio_Dir = config["upload_audio_dir"]
  244. AccessKeyId = config["access_key_id"]
  245. AccessKeySecret = config["access_key_secret"]
  246. }
  247. // S3-OSS相关
  248. {
  249. S3Endpoint = config["s3_endpoint"]
  250. S3BackEndpoint = config["s3_back_endpoint"]
  251. S3BucketName = config["s3_bucket_name"]
  252. S3Host = config["s3_host"]
  253. S3AccessKeyId = config["s3_access_key_id"]
  254. S3AccessKeySecret = config["s3_access_key_secret"]
  255. S3UploadDir = config["s3_upload_dir"]
  256. S3Region = config["s3_region"]
  257. S3ForceStyle = config["s3_force_style"]
  258. S3EndpointPort = config["s3_endpoint_port"]
  259. S3Protocol = config["s3_protocol"]
  260. S3DisableSSL = config["s3_disable_ssl"]
  261. S3OpenAcl = config["s3_open_acl"]
  262. }
  263. }