db.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package utility
  2. import (
  3. elastic "app.yhyue.com/moapp/jybase/es"
  4. "app.yhyue.com/moapp/jypkg/middleground"
  5. "github.com/gogf/gf/v2/frame/g"
  6. "github.com/gogf/gf/v2/os/gctx"
  7. )
  8. type (
  9. mgoConf struct {
  10. Address string
  11. Size int
  12. DbName string
  13. ReplSet string
  14. UserName string
  15. Password string
  16. Collection string
  17. Collection_back string
  18. }
  19. esConf struct {
  20. Address string
  21. Size int
  22. Version string
  23. UserName string
  24. Password string
  25. }
  26. )
  27. var (
  28. elasticConf, otherElasticConf esConf
  29. RedisTime int64
  30. PortraitCount int
  31. OtherElastic elastic.Es
  32. Middleground *middleground.Middleground
  33. )
  34. func init() {
  35. initCtx := gctx.New()
  36. if err := g.Cfg().MustGet(initCtx, "elasticsearch.default").Struct(&elasticConf); err == nil {
  37. elastic.NewEs(elasticConf.Version, elasticConf.Address, elasticConf.Size, elasticConf.UserName, elasticConf.Password)
  38. }
  39. if err := g.Cfg().MustGet(initCtx, "elasticsearch.other").Struct(&otherElasticConf); err == nil {
  40. OtherElastic = &elastic.EsV7{
  41. Address: otherElasticConf.Address,
  42. UserName: otherElasticConf.UserName,
  43. Password: otherElasticConf.Password,
  44. Size: otherElasticConf.Size,
  45. }
  46. OtherElastic.Init()
  47. }
  48. g.Log().Info(initCtx, "初始化 elastic 完成")
  49. RedisTime = g.Cfg().MustGet(initCtx, "redisTime", 7).Int64()
  50. PortraitCount = g.Cfg().MustGet(initCtx, "PortraitCount", 30).Int()
  51. Middleground = middleground.NewMiddleground(g.Cfg().MustGet(initCtx, "etcd.hosts").Strings()).
  52. RegPowerCheckCenter(g.Cfg().MustGet(initCtx, "powerCheckCenterKey").String())
  53. }