blacklist.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "bytes"
  4. "context"
  5. "github.com/pkg/errors"
  6. "github.com/tsuna/gohbase/hrpc"
  7. "go-common/app/interface/live/push-live/model"
  8. "go-common/library/log"
  9. "strconv"
  10. "strings"
  11. )
  12. var (
  13. _hbaseTable = "live:push_blacklist"
  14. _hbaseFamily = "blacklist"
  15. errLinkValueSplit = errors.New("link_value split result nil.")
  16. )
  17. // GetBlackList get blacklist from hbase by target id
  18. func (d *Dao) GetBlackList(c context.Context, task *model.ApPushTask) (mids map[int64]bool, err error) {
  19. var (
  20. key string
  21. result *hrpc.Result
  22. ctx, cancel = context.WithTimeout(c, d.blackListHBaseReadTimeout)
  23. emptyByte = []byte("")
  24. fbytes = []byte(_hbaseFamily)
  25. )
  26. defer cancel()
  27. split := strings.Split(task.LinkValue, ",")
  28. if split == nil {
  29. err = errLinkValueSplit
  30. return
  31. }
  32. key = split[0]
  33. mids = make(map[int64]bool)
  34. if result, err = d.blackListHBase.GetStr(ctx, _hbaseTable, key); err != nil {
  35. log.Error("[dao.blacklist|GetBlackList] d.blackListHBase.Get error(%v) querytable(%v), roomid(%s), task(%v)",
  36. err, _hbaseTable, key, task)
  37. return
  38. }
  39. if result == nil {
  40. return
  41. }
  42. for _, c := range result.Cells {
  43. if c != nil && bytes.Equal(c.Family, fbytes) && !bytes.Equal(c.Qualifier, emptyByte) {
  44. uid, e := strconv.ParseInt(string(c.Qualifier), 10, 64)
  45. if e != nil {
  46. continue
  47. }
  48. mids[uid] = true
  49. }
  50. }
  51. log.Info("[dao.blacklist|GetBlackList] get blacklist(%v), roomid(%s), task(%v)", mids, key, task)
  52. return
  53. }