package utils import ( "fmt" "github.com/beego/beego/v2/core/logs" "github.com/beego/beego/v2/server/web" "rdluck_tools/cache" "rdluck_tools/log" ) var ( RunMode string //运行模式 MYSQL_URL string //数据库连接 MYSQL_URL_RDDP string //数据库连接 REDIS_CACHE string //缓存地址 Rc *cache.Cache //redis缓存 Re error //redis错误 ) var ApiLog *log.Log var ( Bucketname string = "hongze" Endpoint string Imghost string = "https://hongze.oss-accelerate.aliyuncs.com/" Upload_dir string = "static/images/" Upload_Audio_Dir string = "static/audio/" AccessKeyId string = "LTAIFMZYQhS2BTvW" AccessKeySecret string = "12kk1ptCHoGWedhBnKRVW5hRJzq9Fq" ResearchReportUrl = "" //全局加密KEY ) func init() { tmpRunMode, err := web.AppConfig.String("run_mode") if err != nil { panic("配置文件读取run_mode错误 " + err.Error()) } RunMode = tmpRunMode fmt.Println("RunMode:", RunMode) if RunMode == "" { localIp, err := GetLocalIP() fmt.Println("localIp:", localIp) if localIp == "10.0.0.123" { RunMode = "debug" } else { RunMode = "release" } fmt.Println("RunMode:", RunMode) configPath := `/home/code/config/hongze_open_api/conf/app.conf` fmt.Println("configPath:", configPath) err = web.LoadAppConfig("ini", configPath) if err != nil { fmt.Println("web.LoadAppConfig Err:" + err.Error()) } } fmt.Println(RunMode, "模式") config, err := web.AppConfig.GetSection(RunMode) if err != nil { panic("配置文件读取错误 " + err.Error()) } logs.Info(RunMode + " 模式") MYSQL_URL = config["mysql_url"] MYSQL_URL_RDDP = config["mysql_url_rddp"] // 初始化redis REDIS_CACHE = config["beego_cache"] if len(REDIS_CACHE) <= 0 { panic("redis链接参数没有配置") } Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存 if Re != nil { fmt.Println(Re) panic(Re) } //日志类 if RunMode == "release" { logDir := `/data/rdlucklog/hongze_open_api` ApiLog = log.Init("20060102.api", logDir) ResearchReportUrl = "http://8.136.199.33:8608/api/" } else { ApiLog = log.Init("20060102.api") ResearchReportUrl = "http://8.136.199.33:8608/api/" } } //http://webapi.brilliantstart.cn/api/ //http://webapi.brilliantstart.cn/swagger/ //http://139.196.122.219:8603/swagger/