client.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package gorpc
  2. import (
  3. "context"
  4. "go-common/app/service/main/push/model"
  5. "go-common/library/net/rpc"
  6. )
  7. const (
  8. _addReport = "RPC.AddReport"
  9. _delInvalidReports = "RPC.DelInvalidReports"
  10. _delReport = "RPC.DelReport"
  11. _addCallback = "RPC.AddCallback"
  12. _addReportCache = "RPC.AddReportCache"
  13. _addUserReportCache = "RPC.AddUserReportCache"
  14. _setting = "RPC.Setting"
  15. _setSetting = "RPC.SetSetting"
  16. _addMidProgress = "RPC.AddMidProgress"
  17. _addTokenCache = "RPC.AddTokenCache"
  18. _addTokensCache = "RPC.AddTokensCache"
  19. )
  20. var (
  21. // _noArg = &struct{}{}
  22. _noReply = &struct{}{}
  23. _appid = "push.service"
  24. )
  25. // Service struct info.
  26. type Service struct {
  27. client *rpc.Client2
  28. }
  29. // New new service instance and return.
  30. func New(c *rpc.ClientConfig) (s *Service) {
  31. s = &Service{}
  32. s.client = rpc.NewDiscoveryCli(_appid, c)
  33. return
  34. }
  35. // AddReport adds report.
  36. func (s *Service) AddReport(c context.Context, arg *model.ArgReport) (err error) {
  37. err = s.client.Call(c, _addReport, arg, _noReply)
  38. return
  39. }
  40. // DelInvalidReports deletes invalid reports.
  41. func (s *Service) DelInvalidReports(c context.Context, arg *model.ArgDelInvalidReport) (err error) {
  42. err = s.client.Call(c, _delInvalidReports, arg, _noReply)
  43. return
  44. }
  45. // DelReport deletes report.
  46. func (s *Service) DelReport(c context.Context, arg *model.ArgReport) (err error) {
  47. err = s.client.Call(c, _delReport, arg, _noReply)
  48. return
  49. }
  50. // AddCallback adds callback data.
  51. func (s *Service) AddCallback(c context.Context, arg *model.ArgCallback) (err error) {
  52. err = s.client.Call(c, _addCallback, arg, _noReply)
  53. return
  54. }
  55. // AddReportCache adds report.
  56. func (s *Service) AddReportCache(c context.Context, arg *model.ArgReport) (err error) {
  57. err = s.client.Call(c, _addReportCache, arg, _noReply)
  58. return
  59. }
  60. // AddUserReportCache adds user report cache.
  61. func (s *Service) AddUserReportCache(c context.Context, arg *model.ArgUserReports) (err error) {
  62. err = s.client.Call(c, _addUserReportCache, arg, _noReply)
  63. return
  64. }
  65. // Setting gets user push switch setting.
  66. func (s *Service) Setting(c context.Context, arg *model.ArgMid) (res map[int]int, err error) {
  67. err = s.client.Call(c, _setting, arg, &res)
  68. return
  69. }
  70. // SetSetting sets user push switch setting.
  71. func (s *Service) SetSetting(c context.Context, arg *model.ArgSetting) (err error) {
  72. err = s.client.Call(c, _setSetting, arg, _noReply)
  73. return
  74. }
  75. // AddMidProgress adds mid count number to task's progress field
  76. func (s *Service) AddMidProgress(c context.Context, arg *model.ArgMidProgress) (err error) {
  77. err = s.client.Call(c, _addMidProgress, arg, _noReply)
  78. return
  79. }
  80. // AddTokenCache add token cache
  81. func (s *Service) AddTokenCache(ctx context.Context, arg *model.ArgReport) (err error) {
  82. err = s.client.Call(ctx, _addTokenCache, arg, _noReply)
  83. return
  84. }
  85. // AddTokensCache add tokens cache
  86. func (s *Service) AddTokensCache(ctx context.Context, arg *model.ArgReports) (err error) {
  87. err = s.client.Call(ctx, _addTokensCache, arg, _noReply)
  88. return
  89. }