online.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/interface/main/web/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. "go-common/library/net/metadata"
  10. )
  11. // OnlineCount get online count
  12. func (d *Dao) OnlineCount(c context.Context) (data *model.OnlineCount, err error) {
  13. var (
  14. params = url.Values{}
  15. ip = metadata.String(c, metadata.RemoteIP)
  16. )
  17. var res struct {
  18. Code int `json:"code"`
  19. Data *model.OnlineCount `json:"data"`
  20. }
  21. if err = d.httpR.Get(c, d.onlineURL, ip, params, &res); err != nil {
  22. log.Error(" d.httpW.Get.Get(%s) error(%v)", d.onlineURL, err)
  23. return
  24. }
  25. if res.Code != ecode.OK.Code() {
  26. log.Error("d.httpW.Get(%s) code error(%d)", d.onlineURL, res.Code)
  27. err = ecode.Int(res.Code)
  28. return
  29. }
  30. data = res.Data
  31. return
  32. }
  33. // LiveOnlineCount get live online count
  34. func (d *Dao) LiveOnlineCount(c context.Context) (data *model.LiveOnlineCount, err error) {
  35. var (
  36. params = url.Values{}
  37. ip = metadata.String(c, metadata.RemoteIP)
  38. )
  39. var res struct {
  40. Code int `json:"code"`
  41. Data *model.LiveOnlineCount `json:"data"`
  42. }
  43. if err = d.httpR.Get(c, d.liveOnlineURL, ip, params, &res); err != nil {
  44. log.Error(" d.httpW.Get.Get(%s) error(%v)", d.liveOnlineURL, err)
  45. return
  46. }
  47. if res.Code != ecode.OK.Code() {
  48. log.Error("d.httpW.Get(%s) code error(%d)", d.liveOnlineURL, res.Code)
  49. err = ecode.Int(res.Code)
  50. return
  51. }
  52. data = res.Data
  53. return
  54. }
  55. // OnlineList get online list
  56. func (d *Dao) OnlineList(c context.Context, num int64) (data []*model.OnlineAid, err error) {
  57. var (
  58. params = url.Values{}
  59. ip = metadata.String(c, metadata.RemoteIP)
  60. )
  61. params.Set("num", strconv.FormatInt(num, 10))
  62. var res struct {
  63. Code int `json:"code"`
  64. Data []*model.OnlineAid `json:"data"`
  65. }
  66. if err = d.httpR.Get(c, d.onlineListURL, ip, params, &res); err != nil {
  67. log.Error(" d.httpR.Get.Get(%s) error(%v)", d.onlineListURL, err)
  68. return
  69. }
  70. if res.Code != ecode.OK.Code() {
  71. log.Error("d.httpR.Get(%s) code error(%d)", d.onlineListURL, res.Code)
  72. return
  73. }
  74. data = res.Data
  75. return
  76. }