api.go 851 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package archive
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/library/ecode"
  7. "go-common/library/xstr"
  8. "github.com/pkg/errors"
  9. )
  10. const (
  11. _realteURL = "/recsys/related"
  12. )
  13. // RelateAids get relate by aid
  14. func (d *Dao) RelateAids(c context.Context, aid int64, ip string) (aids []int64, err error) {
  15. params := url.Values{}
  16. params.Set("key", strconv.FormatInt(aid, 10))
  17. var res struct {
  18. Code int `json:"code"`
  19. Data []*struct {
  20. Value string `json:"value"`
  21. } `json:"data"`
  22. }
  23. if err = d.client.Get(c, d.relateURL, ip, params, &res); err != nil {
  24. return
  25. }
  26. if res.Code != ecode.OK.Code() {
  27. err = errors.Wrap(ecode.Int(res.Code), d.relateURL+"?"+params.Encode())
  28. return
  29. }
  30. if len(res.Data) != 0 {
  31. if aids, err = xstr.SplitInts(res.Data[0].Value); err != nil {
  32. err = errors.Wrap(err, res.Data[0].Value)
  33. }
  34. }
  35. return
  36. }