audio.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/interface/main/space/model"
  7. "go-common/library/ecode"
  8. "go-common/library/net/metadata"
  9. "go-common/library/xstr"
  10. "github.com/pkg/errors"
  11. )
  12. const (
  13. _audioCntURI = "/x/internal/v1/audio/personal/audio-cnt"
  14. _audioCardURI = "/x/internal/v1/audio/privilege/mcard"
  15. _audioUpperCertURI = "/audio/music-service-c/internal/upper-cert"
  16. )
  17. // AudioCard get audio card info.
  18. func (d *Dao) AudioCard(c context.Context, mid ...int64) (cardm map[int64]*model.AudioCard, err error) {
  19. var (
  20. params = url.Values{}
  21. ip = metadata.String(c, metadata.RemoteIP)
  22. )
  23. params.Set("mid", xstr.JoinInts(mid))
  24. var res struct {
  25. Code int `json:"code"`
  26. Data map[int64]*model.AudioCard `json:"data"`
  27. }
  28. if err = d.httpR.Get(c, d.audioCardURL, ip, params, &res); err != nil {
  29. return
  30. }
  31. if res.Code != ecode.OK.Code() {
  32. err = errors.Wrap(ecode.Int(res.Code), d.audioCardURL+"?"+params.Encode())
  33. return
  34. }
  35. cardm = res.Data
  36. return
  37. }
  38. // AudioUpperCert get audio upper cert.
  39. func (d *Dao) AudioUpperCert(c context.Context, uid int64) (cert *model.AudioUpperCert, err error) {
  40. var (
  41. params = url.Values{}
  42. ip = metadata.String(c, metadata.RemoteIP)
  43. )
  44. params.Set("uid", strconv.FormatInt(uid, 10))
  45. var res struct {
  46. Code int `json:"code"`
  47. Data *model.AudioUpperCert `json:"data"`
  48. }
  49. if err = d.httpR.Get(c, d.audioUpperCertURL, ip, params, &res); err != nil {
  50. return
  51. }
  52. if res.Code != ecode.OK.Code() {
  53. err = errors.Wrap(ecode.Int(res.Code), d.audioUpperCertURL+"?"+params.Encode())
  54. return
  55. }
  56. cert = res.Data
  57. return
  58. }
  59. // AudioCnt get audio cnt.
  60. func (d *Dao) AudioCnt(c context.Context, mid int64) (count int, err error) {
  61. var (
  62. params = url.Values{}
  63. ip = metadata.String(c, metadata.RemoteIP)
  64. )
  65. params.Set("mid", strconv.FormatInt(mid, 10))
  66. var res struct {
  67. Code int `json:"code"`
  68. Data struct {
  69. Song int `json:"song"`
  70. } `json:"data"`
  71. }
  72. if err = d.httpR.Get(c, d.audioCntURL, ip, params, &res); err != nil {
  73. return
  74. }
  75. if res.Code != ecode.OK.Code() {
  76. err = errors.Wrap(ecode.Int(res.Code), d.audioCntURL+"?"+params.Encode())
  77. return
  78. }
  79. count = res.Data.Song
  80. return
  81. }