db.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package utility
  2. import (
  3. elastic "app.yhyue.com/moapp/jybase/es"
  4. "github.com/gogf/gf/v2/frame/g"
  5. "github.com/gogf/gf/v2/os/gctx"
  6. )
  7. type (
  8. esConf struct {
  9. Address string
  10. Size int
  11. Version string
  12. UserName string
  13. Password string
  14. }
  15. )
  16. var (
  17. elasticConf, otherElasticConf esConf
  18. RedisTime int64
  19. PortraitCount int
  20. OtherElastic elastic.Es
  21. )
  22. func init() {
  23. initCtx := gctx.New()
  24. if cfg := g.Cfg().MustGet(initCtx, "elasticsearch.default"); !cfg.IsNil() {
  25. if err := cfg.Struct(&elasticConf); err == nil {
  26. elastic.NewEs(elasticConf.Version, elasticConf.Address, elasticConf.Size, elasticConf.UserName, elasticConf.Password)
  27. }
  28. g.Log().Info(initCtx, "初始化 elastic.default 完成")
  29. }
  30. if cfg := g.Cfg().MustGet(initCtx, "elasticsearch.other"); !cfg.IsNil() {
  31. if err := cfg.Struct(&otherElasticConf); err == nil {
  32. OtherElastic = &elastic.EsV7{
  33. Address: otherElasticConf.Address,
  34. UserName: otherElasticConf.UserName,
  35. Password: otherElasticConf.Password,
  36. Size: otherElasticConf.Size,
  37. }
  38. OtherElastic.Init()
  39. }
  40. g.Log().Info(initCtx, "初始化 elastic.other 完成")
  41. }
  42. }