dao.go 834 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package exp
  2. import (
  3. "context"
  4. "go-common/app/service/live/xuser/conf"
  5. "go-common/library/cache/memcache"
  6. xsql "go-common/library/database/sql"
  7. )
  8. // Dao exp dao
  9. type Dao struct {
  10. c *conf.Config
  11. db *xsql.DB
  12. memcache *memcache.Pool
  13. }
  14. // NewExpDao init mysql db
  15. func NewExpDao(c *conf.Config) (dao *Dao) {
  16. dao = &Dao{
  17. c: c,
  18. db: xsql.NewMySQL(c.UserExpMySQL),
  19. memcache: memcache.NewPool(c.ExpMemcache),
  20. }
  21. return
  22. }
  23. // Close close the resource.
  24. func (d *Dao) Close() {
  25. d.db.Close()
  26. d.memcache.Close()
  27. }
  28. // Ping dao ping
  29. func (d *Dao) Ping(ctx context.Context) error {
  30. // TODO: add mc,redis... if you use
  31. return nil
  32. }
  33. func (d *Dao) getExpire() (respExpire int32) {
  34. if t := conf.Conf.UserExpExpire; t != nil {
  35. respExpire = t.ExpireTime
  36. } else {
  37. respExpire = _emptyExpire
  38. }
  39. return
  40. }