rank.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "go-common/app/interface/openplatform/article/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. var (
  10. _monthURL = "/data/rank/article/all-30.json"
  11. _weekURL = "/data/rank/article/all-7.json"
  12. _yesterDayURL = "/data/rank/article/all-1.json"
  13. _beforeYesterDayURL = "/data/rank/article/all-2.json"
  14. )
  15. // Rank get rank from bigdata
  16. func (d *Dao) Rank(c context.Context, cid int64, ip string) (res model.RankResp, err error) {
  17. var addr string
  18. switch cid {
  19. case model.RankMonth:
  20. addr = _monthURL
  21. case model.RankWeek:
  22. addr = _weekURL
  23. case model.RankYesterday:
  24. addr = _yesterDayURL
  25. case model.RankBeforeYesterday:
  26. addr = _beforeYesterDayURL
  27. default:
  28. err = ecode.RequestErr
  29. return
  30. }
  31. params := url.Values{}
  32. var resp struct {
  33. Code int `json:"code"`
  34. model.RankResp
  35. }
  36. if err = d.httpClient.Get(c, d.c.Article.RankHost+addr, ip, params, &resp); err != nil {
  37. PromError("rank:rank接口")
  38. log.Error("d.client.Get(%s) error(%+v)", addr+"?"+params.Encode(), err)
  39. return
  40. }
  41. if resp.Code != ecode.OK.Code() {
  42. PromError("rank:rank接口")
  43. log.Error("url(%s) res code(%d) or res.result(%+v)", addr+"?"+params.Encode(), resp.Code, resp)
  44. err = ecode.Int(resp.Code)
  45. return
  46. }
  47. res = resp.RankResp
  48. return
  49. }