dao.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/relation/conf"
  6. "go-common/library/cache/memcache"
  7. "go-common/library/cache/redis"
  8. xsql "go-common/library/database/sql"
  9. bm "go-common/library/net/http/blademaster"
  10. )
  11. // Dao struct info of Dao.
  12. type Dao struct {
  13. c *conf.Config
  14. client *bm.Client
  15. //path
  16. clearFollowingPath string
  17. clearFollowerPath string
  18. clearStatPath string
  19. // api path
  20. followersNotify string
  21. // db
  22. db *xsql.DB
  23. // redis
  24. // redis *redis.Pool
  25. // redisExpire int32
  26. // relation cache
  27. relRedis *redis.Pool
  28. relExpire int32
  29. mc *memcache.Pool
  30. // UnreadDuration int64
  31. }
  32. // New new a Dao and return.
  33. func New(c *conf.Config) (dao *Dao) {
  34. dao = &Dao{
  35. c: c,
  36. client: bm.NewClient(c.HTTPClient),
  37. clearFollowingPath: c.ClearPath.Following,
  38. clearFollowerPath: c.ClearPath.Follower,
  39. clearStatPath: c.ClearPath.Stat,
  40. followersNotify: c.ApiPath.FollowersNotify,
  41. db: xsql.NewMySQL(c.Mysql),
  42. // redis: redis.NewPool(c.Redis.Config),
  43. // redisExpire: int32(time.Duration(c.RelRedis.Expire) / time.Second),
  44. relRedis: redis.NewPool(c.RelRedis.Config),
  45. relExpire: int32(time.Duration(c.RelRedis.Expire) / time.Second),
  46. mc: memcache.NewPool(c.Memcache.Config),
  47. // UnreadDuration: int64(time.Duration(c.Relation.FollowersUnread) / time.Second),
  48. }
  49. return dao
  50. }
  51. // Ping ping health of db.
  52. func (d *Dao) Ping(c context.Context) (err error) {
  53. return d.db.Ping(c)
  54. }