dao.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/interface/main/videoup/conf"
  5. upapi "go-common/app/service/main/up/api/v1"
  6. "go-common/library/cache/redis"
  7. bm "go-common/library/net/http/blademaster"
  8. "time"
  9. )
  10. // Dao is archive dao.
  11. type Dao struct {
  12. c *conf.Config
  13. // http
  14. httpR *bm.Client
  15. httpW *bm.Client
  16. UpClient upapi.UpClient
  17. // redis
  18. redis *redis.Pool
  19. redisExpire int32
  20. // uri
  21. viewURI string
  22. addURI string
  23. editURI string
  24. typesURI string
  25. descFormatURI string
  26. tagUpURI string
  27. staffConfigURI string
  28. applyStaffs string
  29. // ad check
  30. porderConfigURL string
  31. gameListURL string
  32. }
  33. const (
  34. _descFormatURL = "/videoup/desc/format"
  35. _porderConfig = "/videoup/porder/config/list"
  36. _gameList = "/game/list"
  37. _staffConfURI = "/x/internal/creative/staff/config"
  38. )
  39. // New new a dao.
  40. func New(c *conf.Config) (d *Dao) {
  41. d = &Dao{
  42. c: c,
  43. //filename redis
  44. redis: redis.NewPool(c.Redis.Videoup.Config),
  45. redisExpire: int32(time.Duration(c.Redis.Videoup.Expire) / time.Second),
  46. // http client
  47. httpR: bm.NewClient(c.HTTPClient.Read),
  48. httpW: bm.NewClient(c.HTTPClient.Write),
  49. // uri
  50. viewURI: c.Host.Archive + _viewURL,
  51. addURI: c.Host.Archive + _addURL,
  52. editURI: c.Host.Archive + _editURL,
  53. typesURI: c.Host.Archive + _typesURL,
  54. descFormatURI: c.Host.Archive + _descFormatURL,
  55. tagUpURI: c.Host.Archive + _tagUpURL,
  56. staffConfigURI: c.Host.APICo + _staffConfURI,
  57. applyStaffs: c.Host.Archive + _applyStaffs,
  58. // ad
  59. porderConfigURL: c.Host.Archive + _porderConfig,
  60. gameListURL: c.Game.OpenHost + _gameList,
  61. }
  62. var err error
  63. if d.UpClient, err = upapi.NewClient(c.UpClient); err != nil {
  64. panic(err)
  65. }
  66. return d
  67. }
  68. // Ping ping success.
  69. func (d *Dao) Ping(c context.Context) (err error) {
  70. if err = d.pingRedis(c); err != nil {
  71. return
  72. }
  73. return
  74. }
  75. // Close close resource.
  76. func (d *Dao) Close() {
  77. if d.redis != nil {
  78. d.redis.Close()
  79. }
  80. }