dao.go 971 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package rank
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-card/model/card/rank"
  5. "go-common/app/interface/main/app-intl/conf"
  6. "go-common/library/ecode"
  7. httpx "go-common/library/net/http/blademaster"
  8. "github.com/pkg/errors"
  9. )
  10. const (
  11. _allRank = "/data/rank/recent_all-app.json"
  12. )
  13. // Dao is rank dao.
  14. type Dao struct {
  15. // http client
  16. clientAsyn *httpx.Client
  17. // all rank
  18. allRank string
  19. }
  20. // New new a rank dao.
  21. func New(c *conf.Config) (d *Dao) {
  22. d = &Dao{
  23. // http client
  24. clientAsyn: httpx.NewClient(c.HTTPClientAsyn),
  25. allRank: c.Host.Rank + _allRank,
  26. }
  27. return d
  28. }
  29. // AllRank is.
  30. func (d *Dao) AllRank(c context.Context) (ranks []*rank.Rank, err error) {
  31. var res struct {
  32. Code int `json:"code"`
  33. List []*rank.Rank `json:"list"`
  34. }
  35. if err = d.clientAsyn.Get(c, d.allRank, "", nil, &res); err != nil {
  36. return
  37. }
  38. if res.Code != ecode.OK.Code() {
  39. err = errors.Wrap(err, d.allRank)
  40. return
  41. }
  42. ranks = res.List
  43. return
  44. }