abserver.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/interface/main/web/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. "go-common/library/net/metadata"
  10. )
  11. const (
  12. _abServerURI = "/abserver/v1/web/match-exp"
  13. )
  14. // AbServer get ab server info.
  15. func (d *Dao) AbServer(c context.Context, mid int64, platform int, channel, buvid string) (res model.AbServer, err error) {
  16. var (
  17. params = url.Values{}
  18. ip = metadata.String(c, metadata.RemoteIP)
  19. )
  20. params.Set("mid", strconv.FormatInt(mid, 10))
  21. params.Set("channel", channel)
  22. params.Set("buvid", buvid)
  23. params.Set("platform", strconv.Itoa(platform))
  24. var data struct {
  25. Code int `json:"errorCode"`
  26. model.AbServer
  27. }
  28. if err = d.httpR.Get(c, d.abServerURL, ip, params, &data); err != nil {
  29. log.Error("AbServer(%s) mid(%d) channel(%s) buvid(%s) error(%v)", d.abServerURL, mid, channel, buvid, err)
  30. return
  31. }
  32. if data.Code != ecode.OK.Code() {
  33. log.Error("AbServer(%s) mid(%d) channel(%s) buvid(%s) code error(%d)", d.abServerURL, mid, channel, buvid, data.Code)
  34. return
  35. }
  36. res = data.AbServer
  37. return
  38. }