http_client.go 893 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _isHotURL = "http://api.bilibili.co/x/internal/v2/reply/ishot"
  11. )
  12. // IsOriginHot return is origin hot reply.
  13. func (d *Dao) IsOriginHot(ctx context.Context, oid, rpID int64, tp int) (isHot bool, err error) {
  14. params := url.Values{}
  15. params.Set("oid", strconv.FormatInt(oid, 10))
  16. params.Set("rpid", strconv.FormatInt(rpID, 10))
  17. params.Set("type", strconv.Itoa(tp))
  18. var res struct {
  19. Code int `json:"code"`
  20. Data *struct {
  21. IsHot bool `json:"isHot"`
  22. } `json:"data"`
  23. }
  24. if err = d.httpCli.Get(ctx, _isHotURL, "", params, &res); err != nil {
  25. log.Error("d.httpCli.Get(%s, %s) error(%v)", _isHotURL, params.Encode(), err)
  26. return
  27. }
  28. if res.Code != ecode.OK.Code() {
  29. err = ecode.Int(res.Code)
  30. return
  31. }
  32. if res.Data != nil {
  33. isHot = res.Data.IsHot
  34. }
  35. return
  36. }