audio.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package audio
  2. import (
  3. "context"
  4. "net/url"
  5. "go-common/app/interface/main/app-card/model/card/audio"
  6. "go-common/app/interface/main/app-channel/conf"
  7. "go-common/library/ecode"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/metadata"
  10. "go-common/library/xstr"
  11. "github.com/pkg/errors"
  12. )
  13. const (
  14. _getAudios = "/x/internal/v1/audio/menus/batch"
  15. _songm = "/x/internal/v1/audio/songs/batch"
  16. )
  17. type Dao struct {
  18. client *bm.Client
  19. getAudios string
  20. songm string
  21. }
  22. func New(c *conf.Config) (d *Dao) {
  23. d = &Dao{
  24. client: bm.NewClient(c.HTTPClient),
  25. getAudios: c.Host.APICo + _getAudios,
  26. songm: c.Host.APICo + _songm,
  27. }
  28. return
  29. }
  30. func (d *Dao) Audios(c context.Context, ids []int64) (aum map[int64]*audio.Audio, err error) {
  31. ip := metadata.String(c, metadata.RemoteIP)
  32. params := url.Values{}
  33. params.Set("ids", xstr.JoinInts(ids))
  34. var res struct {
  35. Code int `json:"code"`
  36. Data map[int64]*audio.Audio `json:"data"`
  37. }
  38. if err = d.client.Get(c, d.getAudios, ip, params, &res); err != nil {
  39. return
  40. }
  41. if res.Code != ecode.OK.Code() {
  42. err = errors.Wrap(ecode.Int(res.Code), d.getAudios+"?"+params.Encode())
  43. return
  44. }
  45. aum = res.Data
  46. return
  47. }