search.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. schmdl "go-common/app/service/main/riot-search/model"
  8. "go-common/library/log"
  9. "go-common/library/net/metadata"
  10. "go-common/library/xstr"
  11. )
  12. const _search = "http://api.bilibili.co/x/internal/riot-search/arc/ids"
  13. // SearchArcs return archive ids by aids.
  14. func (d *Dao) SearchArcs(c context.Context, keyword string, ids []int64, pn, ps int) (res *schmdl.IDsResp, err error) {
  15. params := url.Values{}
  16. params.Set("ids", xstr.JoinInts(ids))
  17. params.Set("keyword", keyword)
  18. params.Set("pn", strconv.Itoa(pn))
  19. params.Set("ps", strconv.Itoa(ps))
  20. ip := metadata.String(c, metadata.RemoteIP)
  21. var (
  22. resp = &struct {
  23. Code int `json:"code"`
  24. Data *schmdl.IDsResp `json:"data"`
  25. }{}
  26. )
  27. if err = d.httpClient.Post(c, _search, ip, params, &resp); err != nil {
  28. log.Error("s.httpClient.Post(%s) error(%v)", _search+"?"+params.Encode(), err)
  29. return
  30. }
  31. log.Info("searchArcs(%s) error(%v)", _search+"?"+params.Encode(), err)
  32. if resp.Code != 0 {
  33. err = fmt.Errorf("code is:%d", resp.Code)
  34. log.Error("s.httpClient.Post(%s) error(%v)", _search+"?"+params.Encode(), err)
  35. return
  36. }
  37. return resp.Data, nil
  38. }