figure.go 1001 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _codeFigureNotFound = 55001
  10. _figureInfoURL = "/x/internal/figure/info"
  11. )
  12. func (d *Dao) figureInfoURI() string {
  13. return d.conf.Host.API + _figureInfoURL
  14. }
  15. // FigureInfo .
  16. func (d *Dao) FigureInfo(c context.Context, mid int64) (score int32, err error) {
  17. var (
  18. res = &struct {
  19. Code int `json:"code"`
  20. Data *struct {
  21. Percentage int32 `json:"percentage"`
  22. } `json:"data"`
  23. }{}
  24. params = url.Values{}
  25. uri = d.figureInfoURI()
  26. )
  27. params.Set("mid", fmt.Sprint(mid))
  28. if err = d.httpClient.Get(c, uri, "", params, &res); err != nil {
  29. log.Error("d.httpClient.Get(%s,%v,%d)", uri, params, err)
  30. return
  31. }
  32. if res.Code != 0 && res.Code != _codeFigureNotFound {
  33. err = fmt.Errorf("code != 0 && code !=%d", _codeFigureNotFound)
  34. log.Error("d.httpClient.Get(%s,%v,%v,%d)", uri, params, err, res.Code)
  35. return
  36. }
  37. if res != nil && res.Data != nil {
  38. score = res.Data.Percentage
  39. }
  40. return
  41. }