dao.go 783 B

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