dao.go 749 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/interface/live/lottery-interface/internal/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. }
  32. // Ping dao ping
  33. func (d *Dao) Ping(ctx context.Context) error {
  34. // TODO: add mc,redis... if you use
  35. return d.db.Ping(ctx)
  36. }