databus.go 779 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package databus
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/interface/main/app-show/conf"
  6. "go-common/library/log"
  7. "go-common/library/queue/databus"
  8. )
  9. // Dao is show dao.
  10. type Dao struct {
  11. // databus
  12. dataBus *databus.Databus
  13. }
  14. func New(c *conf.Config) (d *Dao) {
  15. d = &Dao{
  16. // databus
  17. dataBus: databus.New(c.DislikeDataBus),
  18. }
  19. return
  20. }
  21. func (d *Dao) Pub(ctx context.Context, buvid, gt string, id, mid int64) (err error) {
  22. key := strconv.FormatInt(mid, 10)
  23. msg := struct {
  24. Buvid string `json:"buvid"`
  25. Goto string `json:"goto"`
  26. ID int64 `json:"id"`
  27. Mid int64 `json:"mid"`
  28. }{Buvid: buvid, Goto: gt, ID: id, Mid: mid}
  29. if err = d.dataBus.Send(ctx, key, msg); err != nil {
  30. log.Error("d.dataBus.Pub(%s,%v) error (%v)", key, msg, err)
  31. }
  32. return
  33. }