config.go 7.2 KB

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