dao.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package ups
  2. import (
  3. "context"
  4. "net/url"
  5. "go-common/app/service/main/videoup/conf"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "strconv"
  9. )
  10. const (
  11. _upSpecialURL = "/x/internal/uper/special"
  12. )
  13. // Dao is redis dao.
  14. type Dao struct {
  15. c *conf.Config
  16. httpW *bm.Client
  17. upSpecialURI string
  18. }
  19. // New new a dao.
  20. func New(c *conf.Config) (d *Dao) {
  21. d = &Dao{
  22. c: c,
  23. httpW: bm.NewClient(c.HTTPClient.Write),
  24. upSpecialURI: c.Host.APICO + _upSpecialURL,
  25. }
  26. return d
  27. }
  28. // Ping ping cpdb
  29. func (d *Dao) Ping(c context.Context) (err error) {
  30. return
  31. }
  32. func (d *Dao) upSpecial(c context.Context, groupid string) (ups map[int64]int64, err error) {
  33. params := url.Values{}
  34. params.Set("group_id", groupid)
  35. ups = make(map[int64]int64)
  36. var res struct {
  37. Code int `json:"code"`
  38. Message string `json:"message"`
  39. Data []struct {
  40. Mid int64 `json:"mid"`
  41. } `json:"data"`
  42. }
  43. if err = d.httpW.Get(c, d.upSpecialURI, "", params, &res); err != nil {
  44. log.Error("upSpecial error(%v) | upSpecialURI(%s)", err, d.upSpecialURI)
  45. return
  46. }
  47. log.Info("upSpecial url(%+v)|res(%+v)", d.upSpecialURI, res)
  48. if res.Code != 0 {
  49. log.Error("upSpecial api url(%s) res(%v);, code(%d)", d.upSpecialURI, res, res.Code)
  50. return
  51. }
  52. for _, item := range res.Data {
  53. ups[item.Mid] = item.Mid
  54. }
  55. return
  56. }
  57. // GrayCheckUps GrayCheckUps, type = 8
  58. func (d *Dao) GrayCheckUps(c context.Context, gid int) (checkUps map[int64]int64, err error) {
  59. return d.upSpecial(c, strconv.Itoa(gid))
  60. }