dao.go 753 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/sms/conf"
  5. xsql "go-common/library/database/sql"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/queue/databus"
  8. )
  9. // Dao struct info of Dao.
  10. type Dao struct {
  11. c *conf.Config
  12. db *xsql.DB
  13. client *bm.Client
  14. databus *databus.Databus
  15. }
  16. // New new a Dao and return.
  17. func New(c *conf.Config) (d *Dao) {
  18. d = &Dao{
  19. c: c,
  20. db: xsql.NewMySQL(c.MySQL),
  21. client: bm.NewClient(c.HTTPClient),
  22. databus: databus.New(c.Databus),
  23. }
  24. return
  25. }
  26. // Ping ping health of db.
  27. func (d *Dao) Ping(ctx context.Context) (err error) {
  28. return d.db.Ping(ctx)
  29. }
  30. // Close close connections of mc, redis, db.
  31. func (d *Dao) Close() {
  32. d.db.Close()
  33. d.databus.Close()
  34. }