dao.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package recommend
  2. import (
  3. "time"
  4. "go-common/app/interface/main/app-feed/conf"
  5. "go-common/library/cache/memcache"
  6. "go-common/library/cache/redis"
  7. httpx "go-common/library/net/http/blademaster"
  8. "go-common/library/queue/databus"
  9. )
  10. // Dao is show dao.
  11. type Dao struct {
  12. // http client
  13. client *httpx.Client
  14. clientAsyn *httpx.Client
  15. // hetongzi
  16. hot string
  17. // bigdata
  18. rcmd string
  19. group string
  20. top string
  21. followModeList string
  22. // redis
  23. redis *redis.Pool
  24. expireRds int
  25. // databus
  26. databus *databus.Databus
  27. // mc
  28. mc *memcache.Pool
  29. expireMc int32
  30. }
  31. // New new a show dao.
  32. func New(c *conf.Config) (d *Dao) {
  33. d = &Dao{
  34. // http client
  35. client: httpx.NewClient(c.HTTPData),
  36. clientAsyn: httpx.NewClient(c.HTTPClientAsyn),
  37. // hetongzi
  38. hot: c.Host.Hetongzi + _hot,
  39. // bigdata
  40. rcmd: c.Host.Data + _rcmd,
  41. group: c.Host.BigData + _group,
  42. top: c.Host.Data + _top,
  43. followModeList: c.Host.Data + _followModeList,
  44. // redis
  45. redis: redis.NewPool(c.Redis.Feed.Config),
  46. expireRds: int(time.Duration(c.Redis.Feed.ExpireRecommend) / time.Second),
  47. // databus
  48. databus: databus.New(c.DislikeDatabus),
  49. // mc
  50. mc: memcache.NewPool(c.Memcache.Cache.Config),
  51. expireMc: int32(time.Duration(c.Memcache.Cache.ExpireCache) / time.Second),
  52. }
  53. return
  54. }
  55. // Close close resource.
  56. func (d *Dao) Close() {
  57. if d.redis != nil {
  58. d.redis.Close()
  59. }
  60. if d.mc != nil {
  61. d.mc.Close()
  62. }
  63. }