creative.go 935 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/interface/main/player/model"
  7. "go-common/library/ecode"
  8. "go-common/library/net/metadata"
  9. "github.com/pkg/errors"
  10. )
  11. const _viewPointsURI = "/x/internal/creative/video/viewpoints"
  12. // ViewPoints get view points data from creative.
  13. func (d *Dao) ViewPoints(c context.Context, aid, cid int64) (points []*model.Points, err error) {
  14. params := url.Values{}
  15. params.Set("aid", strconv.FormatInt(aid, 10))
  16. params.Set("cid", strconv.FormatInt(cid, 10))
  17. var res struct {
  18. Code int `json:"code"`
  19. Data struct {
  20. Points []*model.Points `json:"points"`
  21. } `json:"data"`
  22. }
  23. ip := metadata.String(c, metadata.RemoteIP)
  24. if err = d.client.Get(c, d.viewPointsURL, ip, params, &res); err != nil {
  25. return
  26. }
  27. if res.Code != ecode.OK.Code() {
  28. err = errors.Wrap(ecode.Int(res.Code), d.viewPointsURL+"?"+params.Encode())
  29. return
  30. }
  31. points = res.Data.Points
  32. return
  33. }