package common import ( elastic "app.yhyue.com/moapp/jybase/es" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gctx" ) type ( esConf struct { Address string Size int Version string UserName string Password string } ) var ( elasticConf, otherElasticConf esConf RedisTime int64 PortraitCount int OtherElastic elastic.Es ) func init() { initCtx := gctx.New() if cfg := g.Cfg().MustGet(initCtx, "elasticsearch.default"); !cfg.IsNil() { if err := cfg.Struct(&elasticConf); err == nil { elastic.NewEs(elasticConf.Version, elasticConf.Address, elasticConf.Size, elasticConf.UserName, elasticConf.Password) } g.Log().Info(initCtx, "初始化 elastic.default 完成") } if cfg := g.Cfg().MustGet(initCtx, "elasticsearch.other"); !cfg.IsNil() { if err := cfg.Struct(&otherElasticConf); err == nil { OtherElastic = &elastic.EsV7{ Address: otherElasticConf.Address, UserName: otherElasticConf.UserName, Password: otherElasticConf.Password, Size: otherElasticConf.Size, } OtherElastic.Init() } g.Log().Info(initCtx, "初始化 elastic.other 完成") } }