123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- package utils
- import (
- "fmt"
- beeLogger "github.com/beego/bee/v2/logger"
- "github.com/beego/beego/v2/server/web"
- "github.com/qiniu/qmgo"
- "strconv"
- )
- var (
- RunMode string //运行模式
- MYSQL_URL string //数据库连接
- MYSQL_URL_DATA string
- MYSQL_URL_RDDP string
- MgoUrlData string // mongodb数据库连接配置
- REDIS_CACHE string //缓存地址
- //Rc *cache.Cache //redis缓存
- Re error //redis错误
- Rc RedisClient //redis缓存
- MgoDataCli *qmgo.Client // mongodb客户端连接
- MgoDataDbName string // mongodb指标数据的库名
- )
- // 日志配置
- var (
- LogPath string //调用过程中的日志存放地址
- LogFile string
- BinLogPath string //数据库相关的日志存放地址
- BinLogFile string
- ApiLogPath string //接口请求地址和接口返回值日志存放地址
- ApiLogFile string
- LogMaxDays int //日志最大保留天数
- )
- var (
- BusinessCode string //商家编码
- AppId string
- Secret string
- )
- // ES索引配置
- var (
- EsReportIndexName string //研报ES索引
- EsEnglishReportIndexName string //英文研报ES索引
- SmartReportIndexName string //智能研报ES索引
- )
- // ES配置
- var (
- ES_URL string // ES服务器地址
- ES_USERNAME string // ES账号
- ES_PASSWORD string // ES密码
- )
- // 内部配置
- var (
- EdbChartLibUrl string // 图库服务地址
- // EDB_LIB_URL 公共指标库
- EDB_LIB_URL string
- APP_EDB_LIB_NAME_EN string
- EDB_LIB_Md5_KEY string
- )
- func init() {
- tmpRunMode, err := web.AppConfig.String("run_mode")
- if err != nil {
- panic("配置文件读取run_mode错误 " + err.Error())
- }
- RunMode = tmpRunMode
- if RunMode == "" {
- localIp, err := GetLocalIP()
- fmt.Println("localIp:", localIp)
- if localIp == "10.0.0.123" {
- RunMode = "debug"
- } else {
- RunMode = "release"
- }
- configPath := `/home/code/config/eta_hub/conf/app.conf`
- err = web.LoadAppConfig("ini", configPath)
- if err != nil {
- fmt.Println("web.LoadAppConfig Err:" + err.Error())
- }
- }
- config, err := web.AppConfig.GetSection(RunMode)
- if err != nil {
- panic("配置文件读取错误 " + err.Error())
- }
- beeLogger.Log.Info(RunMode + " 模式")
- MYSQL_URL = config["mysql_url"]
- MYSQL_URL_DATA = config["mysql_url_data"]
- MYSQL_URL_RDDP = config["mysql_url_rddp"]
- // mongodb数据库连接配置
- MgoUrlData = config["mgo_url_data"]
- REDIS_CACHE = config["beego_cache"]
- if len(REDIS_CACHE) <= 0 {
- panic(any("redis链接参数没有配置"))
- }
- //Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
- //if Re != nil {
- // fmt.Println(Re)
- // panic(any(Re))
- //}
- // 初始化缓存
- redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
- if err != nil {
- fmt.Println("redis链接异常:", err)
- panic(any(Re))
- }
- Rc = redisClient
- //商家编码
- BusinessCode = config["business_code"]
- if BusinessCode == "" {
- panic("商家编码未配置,请先配置商家编码")
- }
- AppId = config["appid"]
- if AppId == "" {
- panic("appid未配置")
- }
- Secret = config["secret"]
- if Secret == "" {
- panic("secret未配置")
- }
- //日志配置
- {
- LogPath = config["log_path"]
- LogFile = config["log_file"]
- BinLogPath = config["binlog_path"]
- BinLogFile = config["binlog_file"]
- ApiLogPath = config["apilog_path"]
- ApiLogFile = config["apilog_file"]
- logMaxDaysStr := config["log_max_day"]
- LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
- }
- // ES 索引
- {
- EsReportIndexName = config["es_report_index_name"]
- EsEnglishReportIndexName = config["es_english_report_index_name"]
- SmartReportIndexName = config["es_smart_report_index_name"]
- }
- // ES配置
- {
- ES_URL = config["es_url"]
- ES_USERNAME = config["es_username"]
- ES_PASSWORD = config["es_password"]
- }
- // 内部配置
- {
- EdbChartLibUrl = config["edb_chart_lib_url"]
- // 公共指标库相关
- EDB_LIB_URL = config["edb_lib_url"]
- APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
- EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
- }
- }
|