bigdata.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package dao
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "net/url"
  7. "strconv"
  8. "go-common/library/log"
  9. "go-common/library/net/metadata"
  10. )
  11. const (
  12. _uri = "/danmaku/%d/rec"
  13. )
  14. func (d *Dao) danmakuURI(oid int64) string {
  15. return d.conf.Host.AI + fmt.Sprintf(_uri, oid%4)
  16. }
  17. // RecFlag get recommend flags from bigdata.
  18. func (d *Dao) RecFlag(c context.Context, mid, aid, oid, limit, ps, pe int64, plat int32) (data []byte, err error) {
  19. var res struct {
  20. Code int64 `json:"code"`
  21. Msg string `json:"message"`
  22. Data json.RawMessage `json:"data"`
  23. }
  24. uri := d.danmakuURI(oid)
  25. params := url.Values{}
  26. realIP := metadata.String(c, metadata.RemoteIP)
  27. params.Set("mid", strconv.FormatInt(mid, 10))
  28. params.Set("aid", strconv.FormatInt(aid, 10))
  29. params.Set("oid", strconv.FormatInt(oid, 10))
  30. params.Set("limit", strconv.FormatInt(limit, 10))
  31. params.Set("ps", strconv.FormatInt(ps, 10))
  32. params.Set("pe", strconv.FormatInt(pe, 10))
  33. params.Set("plat", strconv.FormatInt(int64(plat), 10))
  34. params.Set("ip", realIP)
  35. if err = d.httpCli.Get(c, uri, realIP, params, &res); err != nil {
  36. PromError(uri)
  37. log.Error("d.httpCli.Get(%s?%s) error(%v)", uri, params.Encode(), err)
  38. return
  39. }
  40. if res.Code != 0 {
  41. PromError(uri)
  42. log.Error("d.httpCli.Get(%s?%s) code:%d msg:%s", uri, params.Encode(), res.Code, res.Msg)
  43. err = fmt.Errorf("bigdata response code(%d) error", res.Code)
  44. return
  45. }
  46. data = res.Data
  47. return
  48. }