dao.go 851 B

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