dao.go 745 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/live/fans_medal/conf"
  5. "go-common/library/cache/memcache"
  6. "go-common/library/cache/redis"
  7. xsql "go-common/library/database/sql"
  8. )
  9. // Dao dao
  10. type Dao struct {
  11. c *conf.Config
  12. mc *memcache.Pool
  13. redis *redis.Pool
  14. db *xsql.DB
  15. }
  16. // New init mysql db
  17. func New(c *conf.Config) (dao *Dao) {
  18. dao = &Dao{
  19. c: c,
  20. mc: memcache.NewPool(c.Memcache),
  21. redis: redis.NewPool(c.Redis),
  22. db: xsql.NewMySQL(c.MySQL),
  23. }
  24. return
  25. }
  26. // Close close the resource.
  27. func (d *Dao) Close() {
  28. d.mc.Close()
  29. d.redis.Close()
  30. d.db.Close()
  31. return
  32. }
  33. // Ping dao ping
  34. func (d *Dao) Ping(c context.Context) error {
  35. // TODO: if you need use mc,redis, please add
  36. return d.db.Ping(c)
  37. }