dao.go 621 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/card/conf"
  5. "go-common/library/cache/memcache"
  6. xsql "go-common/library/database/sql"
  7. )
  8. // Dao dao
  9. type Dao struct {
  10. c *conf.Config
  11. mc *memcache.Pool
  12. db *xsql.DB
  13. }
  14. // New init mysql db
  15. func New(c *conf.Config) (dao *Dao) {
  16. dao = &Dao{
  17. c: c,
  18. mc: memcache.NewPool(c.Memcache.Config),
  19. db: xsql.NewMySQL(c.MySQL),
  20. }
  21. return
  22. }
  23. // Close close the resource.
  24. func (d *Dao) Close() {
  25. d.mc.Close()
  26. d.db.Close()
  27. }
  28. // Ping dao ping
  29. func (d *Dao) Ping(c context.Context) (err error) {
  30. if err = d.pingMC(c); err != nil {
  31. return
  32. }
  33. return d.db.Ping(c)
  34. }