client.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package client
  2. import (
  3. "context"
  4. "go-common/app/service/main/resource/model"
  5. "go-common/library/net/rpc"
  6. )
  7. var (
  8. _noArg = &struct{}{}
  9. )
  10. const (
  11. _resourceAll = "RPC.ResourceAll"
  12. _assignmentAll = "RPC.AssignmentAll"
  13. _defBanner = "RPC.DefBanner"
  14. _resource = "RPC.Resource"
  15. _resources = "RPC.Resources"
  16. _banners = "RPC.Banners"
  17. _pasterAPP = "RPC.PasterAPP"
  18. _indexIcon = "RPC.IndexIcon"
  19. _playerIcon = "RPC.PlayerIcon"
  20. _cmtbox = "RPC.Cmtbox"
  21. _sidebars = "RPC.SideBars"
  22. _abtest = "RPC.AbTest"
  23. _pasterCID = "RPC.PasterCID"
  24. // app id
  25. _appid = "resource.service"
  26. )
  27. // Service is resource rpc client.
  28. type Service struct {
  29. client *rpc.Client2
  30. }
  31. // New new a resource rpc client.
  32. func New(c *rpc.ClientConfig) (s *Service) {
  33. s = &Service{}
  34. s.client = rpc.NewDiscoveryCli(_appid, c)
  35. return
  36. }
  37. // ResourceAll get all resource.
  38. func (s *Service) ResourceAll(c context.Context) (res []*model.Resource, err error) {
  39. err = s.client.Call(c, _resourceAll, _noArg, &res)
  40. return
  41. }
  42. // AssignmentAll get all assignment.
  43. func (s *Service) AssignmentAll(c context.Context) (res []*model.Assignment, err error) {
  44. err = s.client.Call(c, _assignmentAll, _noArg, &res)
  45. return
  46. }
  47. // DefBanner get default banner.
  48. func (s *Service) DefBanner(c context.Context) (res *model.Assignment, err error) {
  49. res = new(model.Assignment)
  50. err = s.client.Call(c, _defBanner, _noArg, res)
  51. return
  52. }
  53. // Resource get resource.
  54. func (s *Service) Resource(c context.Context, arg *model.ArgRes) (res *model.Resource, err error) {
  55. res = new(model.Resource)
  56. err = s.client.Call(c, _resource, arg, res)
  57. return
  58. }
  59. // Resources get resource.
  60. func (s *Service) Resources(c context.Context, arg *model.ArgRess) (res map[int]*model.Resource, err error) {
  61. err = s.client.Call(c, _resources, arg, &res)
  62. return
  63. }
  64. // Banners get banners.
  65. func (s *Service) Banners(c context.Context, arg *model.ArgBanner) (res *model.Banners, err error) {
  66. err = s.client.Call(c, _banners, arg, &res)
  67. return
  68. }
  69. // PasterAPP get paster.
  70. func (s *Service) PasterAPP(c context.Context, arg *model.ArgPaster) (res *model.Paster, err error) {
  71. res = new(model.Paster)
  72. err = s.client.Call(c, _pasterAPP, arg, res)
  73. return
  74. }
  75. // IndexIcon get index icons.
  76. func (s *Service) IndexIcon(c context.Context) (res map[string][]*model.IndexIcon, err error) {
  77. err = s.client.Call(c, _indexIcon, _noArg, &res)
  78. return
  79. }
  80. // PlayerIcon get palyer config.
  81. func (s *Service) PlayerIcon(c context.Context) (res *model.PlayerIcon, err error) {
  82. res = new(model.PlayerIcon)
  83. err = s.client.Call(c, _playerIcon, _noArg, res)
  84. return
  85. }
  86. // Cmtbox get live box
  87. func (s *Service) Cmtbox(c context.Context, arg *model.ArgCmtbox) (res *model.Cmtbox, err error) {
  88. err = s.client.Call(c, _cmtbox, arg, &res)
  89. return
  90. }
  91. // SideBars get side bar.
  92. func (s *Service) SideBars(c context.Context) (res *model.SideBars, err error) {
  93. res = new(model.SideBars)
  94. err = s.client.Call(c, _sidebars, _noArg, res)
  95. return
  96. }
  97. // AbTest get abtest.
  98. func (s *Service) AbTest(c context.Context, arg *model.ArgAbTest) (res map[string]*model.AbTest, err error) {
  99. err = s.client.Call(c, _abtest, arg, &res)
  100. return
  101. }
  102. // PasterCID get all Paster's cid.
  103. func (s *Service) PasterCID(c context.Context) (res map[int64]int64, err error) {
  104. err = s.client.Call(c, _pasterCID, _noArg, &res)
  105. return
  106. }