package conf import ( "AIOTCOER/logs" "fmt" beego "github.com/beego/beego/v2/server/web" "math/rand" "os" "strings" "time" ) func init() { dir, err := os.Getwd() if err != nil { dir = "/tmp" } Analysis_Dir = dir + "/Plugin/Prot/" logs.Println("Analysis_Dir:", Analysis_Dir) Config_AdminTokey, err = beego.AppConfig.String("Config_AdminTokey") //fmt.Println("AdminTokey:",Config_AdminTokey,err) if err != nil || len(Config_AdminTokey) == 0{ Config_AdminTokey = GetRandstring(32, "", 1) fmt.Println("AdminTokey:",Config_AdminTokey) } } var HTTPPort, _ = beego.AppConfig.Int("httpport") var AppName, _ = beego.AppConfig.String("appname") // Redis var Redis_address, _ = beego.AppConfig.String("Redis_address") var Redis_password, _ = beego.AppConfig.String("Redis_password") var Redis_dbNum, _ = beego.AppConfig.String("Redis_dbNum") // Mysql var MysqlServer_UrlPort, _ = beego.AppConfig.String("MysqlServer_UrlPort") var MysqlServer_Database, _ = beego.AppConfig.String("MysqlServer_Database") var MysqlServer_Username, _ = beego.AppConfig.String("MysqlServer_Username") var MysqlServer_Password, _ = beego.AppConfig.String("MysqlServer_Password") var MysqlServer_MaxIdleConnections, _ = beego.AppConfig.Int("MysqlServer_MaxIdleConnections") var MysqlServer_MaxOpenConnections, _ = beego.AppConfig.Int("MysqlServer_MaxOpenConnections") // Mongodb var Mongodb_Url, _ = beego.AppConfig.String("Mongodb_Url") var Mongodb_DB, _ = beego.AppConfig.String("Mongodb_DB") var Mongodb_Username, _ = beego.AppConfig.String("Mongodb_Username") var Mongodb_Password, _ = beego.AppConfig.String("Mongodb_Password") // 数据解析加载目录 var Analysis_Dir string // 管理 var Config_AddProductType, _ = beego.AppConfig.Bool("Config_AddProductType") // 是否可以添加产品 var Config_AdminTokey string // 管理员秘钥 // Qiniu var Qiniu_AccessKey, _ = beego.AppConfig.String("Qiniu_AccessKey") var Qiniu_SecretKey, _ = beego.AppConfig.String("Qiniu_SecretKey") var Qiniu_BUCKET, _ = beego.AppConfig.String("Qiniu_BUCKET") var Qiniu_Url, _ = beego.AppConfig.String("Qiniu_Url") // #取得随机字符串:通过打乱slice来操作 func GetRandstring(length int, char string, rand_x int64) string { if length < 1 { return "" } if len(char) <= 6 || len(char) <= length { char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" } charArr := strings.Split(char, "") ran := rand.New(rand.NewSource(time.Now().Unix() + rand_x)) l := len(charArr) for i := l - 1; i > 0; i-- { r := ran.Intn(i) charArr[r], charArr[i] = charArr[i], charArr[r] } rchar := charArr[:length] return strings.Join(rchar, "") }