search.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/interface/main/playlist/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. "go-common/library/net/metadata"
  8. "net/url"
  9. "strconv"
  10. )
  11. const (
  12. _searchURL = "/main/search"
  13. _searchVer = "v3"
  14. _platform = "web"
  15. _searchType = "video"
  16. _searchFrom = "web_playlist"
  17. )
  18. // SearchVideo get search video.
  19. func (d *Dao) SearchVideo(c context.Context, pn, ps int, query string) (res []*model.SearchArc, count int, err error) {
  20. var (
  21. params = url.Values{}
  22. ip = metadata.String(c, metadata.RemoteIP)
  23. )
  24. params.Set("main_ver", _searchVer)
  25. params.Set("platform", _platform)
  26. params.Set("search_type", _searchType)
  27. params.Set("from_source", _searchFrom)
  28. params.Set("pagesize", strconv.Itoa(ps))
  29. params.Set("page", strconv.Itoa(pn))
  30. params.Set("keyword", query)
  31. params.Set("clientip", ip)
  32. var rs struct {
  33. Code int `json:"code"`
  34. Result []*model.SearchArc `json:"result"`
  35. NumResults int `json:"numResults"`
  36. }
  37. if err = d.http.Get(c, d.searchURL, ip, params, &rs); err != nil {
  38. log.Error("d.http.Get(%s,%v) error(%v)", d.searchURL, params, err)
  39. return
  40. }
  41. if rs.Code != ecode.OK.Code() {
  42. log.Error("d.http.Get(%s,%v) code error(%v)", d.searchURL, params, rs.Code)
  43. return
  44. }
  45. res = rs.Result
  46. count = rs.NumResults
  47. return
  48. }