12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package utils
- import (
- "fmt"
- beeLogger "github.com/beego/bee/v2/logger"
- "github.com/beego/beego/v2/server/web"
- "github.com/rdlucklib/rdluck_tools/cache"
- )
- var (
- RunMode string //运行模式
- MYSQL_URL string //数据库连接
- REDIS_CACHE string //缓存地址
- Rc *cache.Cache //redis缓存
- Re error //redis错误
- )
- var (
- STATIC_DIR 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"
- }
- fmt.Println("RunMode:", RunMode)
- configPath := `/home/code/config/hongze_robot/conf/app.conf`
- fmt.Println("configPath:", configPath)
- 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"]
- REDIS_CACHE = config["beego_cache"]
- Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
- if Re != nil {
- fmt.Println(Re)
- panic(Re)
- }
- if RunMode == "release" {
- } else {
- }
- }
|