db.go 990 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package utility
  2. import (
  3. m "app.yhyue.com/moapp/jybase/mongodb"
  4. "context"
  5. "fmt"
  6. "github.com/gogf/gf/v2/frame/g"
  7. "github.com/gogf/gf/v2/os/gctx"
  8. "jybxseo/internal/consts"
  9. )
  10. type (
  11. mgoConf struct {
  12. Address string
  13. Size int
  14. DbName string
  15. ReplSet string
  16. UserName string
  17. Password string
  18. Collection string
  19. Collection_back string
  20. }
  21. )
  22. var (
  23. mongdbConf mgoConf
  24. Mgo m.MongodbSim
  25. )
  26. func init() {
  27. initCtx := gctx.New()
  28. fmt.Println(consts.CityType)
  29. if err := g.Cfg().MustGet(initCtx, "mongodb").Struct(&mongdbConf); err != nil {
  30. panic(err)
  31. }
  32. Mgo = m.MongodbSim{
  33. MongodbAddr: mongdbConf.Address,
  34. Size: mongdbConf.Size,
  35. DbName: mongdbConf.DbName,
  36. UserName: mongdbConf.UserName,
  37. Password: mongdbConf.Password,
  38. ReplSet: mongdbConf.ReplSet,
  39. }
  40. Mgo.InitPool()
  41. if err := g.Cfg().MustGet(context.Background(), "entMongodb").Struct(&mongdbConf); err != nil {
  42. panic(err)
  43. }
  44. }