dynamic.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 _Dynamic = "http://api.vc.bilibili.co/dynamic_repost/v0/dynamic_repost/view_repost"
  10. // DynamicCount get dynamic count from api
  11. func (d *Dao) DynamicCount(c context.Context, aid int64) (count int64, err error) {
  12. params := url.Values{}
  13. params.Set("rid", strconv.FormatInt(aid, 10))
  14. params.Set("type", "64")
  15. params.Set("offset", "0")
  16. var res struct {
  17. Code int `json:"errno"`
  18. Msg string `json:"msg"`
  19. Data struct {
  20. TotalCount int64 `json:"total_count"`
  21. } `json:"data"`
  22. }
  23. err = d.httpClient.Get(c, _Dynamic, "", params, &res)
  24. if err != nil {
  25. PromError("count:dynamic")
  26. log.Error("dynamic: d.client.Get(%s) error(%+v)", _Dynamic+"?"+params.Encode(), err)
  27. return
  28. }
  29. if res.Code != 0 {
  30. PromError("count:dynamic接口")
  31. log.Error("dynamic: url(%s) res code(%d) msg: %s", _Dynamic+"?"+params.Encode(), res.Code, res.Msg)
  32. err = ecode.Int(res.Code)
  33. return
  34. }
  35. count = res.Data.TotalCount
  36. return
  37. }