dao.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package like
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/activity/conf"
  6. "go-common/library/cache/memcache"
  7. "go-common/library/cache/redis"
  8. "go-common/library/database/elastic"
  9. "go-common/library/database/sql"
  10. "go-common/library/net/http/blademaster"
  11. )
  12. const _activity = "activity"
  13. // Dao dao
  14. type Dao struct {
  15. db *sql.DB
  16. subjectStmt *sql.Stmt
  17. inOnlineLog *sql.Stmt
  18. mcLike *memcache.Pool
  19. mcLikeExpire int32
  20. redis *redis.Pool
  21. redisExpire int32
  22. httpClient *blademaster.Client
  23. es *elastic.Elastic
  24. setObjStatURL string
  25. setViewRankURL string
  26. setLikeContentURL string
  27. addLotteryTimesURL string
  28. }
  29. // New init
  30. func New(c *conf.Config) (d *Dao) {
  31. d = &Dao{
  32. db: sql.NewMySQL(c.MySQL.Like),
  33. mcLike: memcache.NewPool(c.Memcache.Like),
  34. mcLikeExpire: int32(time.Duration(c.Memcache.LikeExpire) / time.Second),
  35. redis: redis.NewPool(c.Redis.Config),
  36. redisExpire: int32(time.Duration(c.Redis.Expire) / time.Second),
  37. httpClient: blademaster.NewClient(c.HTTPClient),
  38. es: elastic.NewElastic(c.Elastic),
  39. setObjStatURL: c.Host.APICo + _setObjStatURI,
  40. setViewRankURL: c.Host.APICo + _setViewRankURI,
  41. setLikeContentURL: c.Host.APICo + _setLikeContentURI,
  42. addLotteryTimesURL: c.Host.Activity + _addLotteryTimesURI,
  43. }
  44. d.subjectStmt = d.db.Prepared(_selSubjectSQL)
  45. d.inOnlineLog = d.db.Prepared(_inOnlineLogSQL)
  46. return
  47. }
  48. // Close close
  49. func (d *Dao) Close() {
  50. d.db.Close()
  51. }
  52. // Ping ping
  53. func (d *Dao) Ping(c context.Context) error {
  54. return d.db.Ping(c)
  55. }