1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package init
- import (
- MC "app.yhyue.com/moapp/jybase/common"
- "flag"
- "github.com/zeromicro/go-zero/core/conf"
- "jyBXCore/api/internal/config"
- "log"
- "regexp"
- "time"
- )
- var configFile = flag.String("cf", "etc/bxcore-api.yaml", "the config file")
- var C config.Config
- var dbFile = flag.String("df", "etc/db.yaml", "the db file")
- var DB config.Db
- var routesFile = flag.String("rf", "etc/routes.yaml", "the routes file")
- var Routes config.Routes
- var ExcludeUrl = []*regexp.Regexp{}
- var HotKeyArrLoginEd, HotKeyArrUnLogin []string
- func init() {
- log.Println("初始化配置")
- //读取基础配置
- conf.MustLoad(*configFile, &C)
- //读取数据库配置
- conf.MustLoad(*dbFile, &DB)
- //初始redis
- RedisInit(&DB.Redis)
- //初始mongodb
- MongoDBInit(&DB.Mongo)
- //读取路由配置
- conf.MustLoad(*routesFile, &Routes)
- if len(Routes.ExcludeRoute) > 0 {
- for _, v := range Routes.ExcludeRoute {
- ExcludeUrl = append(ExcludeUrl, regexp.MustCompile(MC.ObjToString(v)))
- }
- }
- // 每隔5分钟更新一次随机词
- go func() {
- HotKeyArrLoginEd, HotKeyArrUnLogin = GetIndexHotKey(), getIndexHotKeyNoLoginFunc()
- for range time.NewTicker(300 * time.Second).C {
- HotKeyArrLoginEd, HotKeyArrUnLogin = GetIndexHotKey(), getIndexHotKeyNoLoginFunc()
- }
- }()
- }
- var getIndexHotKeyNoLoginFunc = func() (loginEd []string) {
- // 定义一个函数,用于从数组words中随机取出几个词
- m := map[string]bool{}
- for _, v := range C.MobileIndexHotKeyUnLogin {
- m[v] = true
- }
- for key, _ := range m {
- loginEd = append(loginEd, key)
- if len(loginEd) == int(C.MobileIndexHotKeyLimit) {
- break
- }
- }
- return
- }
- func GetIndexHotKey() (loginEd []string) {
- // 定义一个函数,用于从数组words中随机取出几个词
- m := map[string]bool{}
- for _, v := range C.MobileIndexHotKey {
- m[v] = true
- }
- for key, _ := range m {
- loginEd = append(loginEd, key)
- if len(loginEd) == int(C.MobileIndexHotKeyLimit) {
- break
- }
- }
- return
- }
|