dao.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package bgm
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/service/main/videoup/conf"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. const (
  11. _bgmBindURI = "/x/internal/v1/audio/song_video_relation/add"
  12. )
  13. // Dao is redis dao.
  14. type Dao struct {
  15. c *conf.Config
  16. httpW *bm.Client
  17. bgmBindURL string
  18. }
  19. // New new a dao.
  20. func New(c *conf.Config) (d *Dao) {
  21. d = &Dao{
  22. c: c,
  23. httpW: bm.NewClient(c.HTTPClient.Write),
  24. bgmBindURL: c.Host.APICO + _bgmBindURI,
  25. }
  26. return d
  27. }
  28. // Ping ping cpdb
  29. func (d *Dao) Ping(c context.Context) (err error) {
  30. return
  31. }
  32. // Bind aid,sid,cid bind in one
  33. func (d *Dao) Bind(c context.Context, aid, sid, cid int64) (err error) {
  34. params := url.Values{}
  35. params.Set("aid", strconv.FormatInt(aid, 10))
  36. params.Set("sid", strconv.FormatInt(sid, 10))
  37. params.Set("cid", strconv.FormatInt(cid, 10))
  38. var res struct {
  39. Code int `json:"code"`
  40. }
  41. if err = d.httpW.Post(c, d.bgmBindURL, "", params, &res); err != nil {
  42. log.Error("d.httpW.Post(%s) error(%v)", d.bgmBindURL+"?"+params.Encode(), err)
  43. return
  44. }
  45. if res.Code != 0 {
  46. log.Error("url(%s) code(%d)", d.bgmBindURL+"?"+params.Encode(), res.Code)
  47. }
  48. return
  49. }