server.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package server
  2. import (
  3. "go-common/app/service/main/resource/conf"
  4. "go-common/app/service/main/resource/model"
  5. "go-common/app/service/main/resource/service"
  6. "go-common/library/ecode"
  7. "go-common/library/net/rpc"
  8. "go-common/library/net/rpc/context"
  9. )
  10. // RPC struct
  11. type RPC struct {
  12. s *service.Service
  13. }
  14. // New init rpc server.
  15. func New(c *conf.Config, s *service.Service) (svr *rpc.Server) {
  16. r := &RPC{s: s}
  17. svr = rpc.NewServer(c.RPCServer)
  18. if err := svr.Register(r); err != nil {
  19. panic(err)
  20. }
  21. return
  22. }
  23. // Ping check connection success.
  24. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  25. return
  26. }
  27. // ResourceAll get all resource.
  28. func (r *RPC) ResourceAll(c context.Context, a *struct{}, res *[]*model.Resource) (err error) {
  29. *res = r.s.ResourceAll(c)
  30. return
  31. }
  32. // AssignmentAll get all assignment.
  33. func (r *RPC) AssignmentAll(c context.Context, a *struct{}, res *[]*model.Assignment) (err error) {
  34. *res = r.s.AssignmentAll(c)
  35. return
  36. }
  37. // DefBanner get default banner.
  38. func (r *RPC) DefBanner(c context.Context, a *struct{}, as *model.Assignment) (err error) {
  39. res := r.s.DefBanner(c)
  40. if res == nil {
  41. err = ecode.NothingFound
  42. return
  43. }
  44. *as = *res
  45. return
  46. }
  47. // Resource get resource.
  48. func (r *RPC) Resource(c context.Context, arg *model.ArgRes, res *model.Resource) (err error) {
  49. rs := r.s.Resource(c, arg.ResID)
  50. if rs == nil {
  51. err = ecode.NothingFound
  52. return
  53. }
  54. *res = *rs
  55. return
  56. }
  57. // Resources get resource.
  58. func (r *RPC) Resources(c context.Context, as *model.ArgRess, res *map[int]*model.Resource) (err error) {
  59. *res = r.s.Resources(c, as.ResIDs)
  60. return
  61. }
  62. // Banners get banners.
  63. func (r *RPC) Banners(c context.Context, ab *model.ArgBanner, res *model.Banners) (err error) {
  64. // func Banners already new rs, rs can not be nil.
  65. rs := r.s.Banners(c, ab.Plat, ab.Build, ab.AID, ab.MID, ab.ResIDs, ab.Channel, ab.IP, ab.Buvid, ab.Network, ab.MobiApp, ab.Device, ab.OpenEvent, ab.AdExtra, ab.Version, ab.IsAd)
  66. *res = *rs
  67. return
  68. }
  69. // PasterAPP get paster for APP.
  70. func (r *RPC) PasterAPP(c context.Context, arg *model.ArgPaster, res *model.Paster) (err error) {
  71. var rs *model.Paster
  72. if rs, err = r.s.PasterAPP(c, arg.Platform, arg.AdType, arg.Aid, arg.TypeId, arg.Buvid); err == nil {
  73. *res = *rs
  74. }
  75. return
  76. }
  77. // IndexIcon get index icon.
  78. func (r *RPC) IndexIcon(c context.Context, a *struct{}, res *map[string][]*model.IndexIcon) (err error) {
  79. *res = r.s.IndexIcon(c)
  80. return
  81. }
  82. // PlayerIcon get player icon config.
  83. func (r *RPC) PlayerIcon(c context.Context, arg *struct{}, res *model.PlayerIcon) (err error) {
  84. var rs *model.PlayerIcon
  85. rs, err = r.s.PlayerIcon(c)
  86. if err == nil {
  87. *res = *rs
  88. }
  89. return
  90. }
  91. // Cmtbox get live box.
  92. func (r *RPC) Cmtbox(c context.Context, cb *model.ArgCmtbox, res *model.Cmtbox) (err error) {
  93. rs, err := r.s.Cmtbox(c, cb.ID)
  94. if err == nil {
  95. *res = *rs
  96. }
  97. return
  98. }
  99. // SideBars get sode bar.
  100. func (r *RPC) SideBars(c context.Context, a *struct{}, res *model.SideBars) (err error) {
  101. sbs := r.s.SideBars(c)
  102. *res = *sbs
  103. return
  104. }
  105. // AbTest get abtest.
  106. func (r *RPC) AbTest(c context.Context, ab *model.ArgAbTest, res *map[string]*model.AbTest) (err error) {
  107. *res = r.s.AbTest(c, ab.Groups, ab.IP)
  108. return
  109. }
  110. // PasterCID get all Paster's cid.
  111. func (r *RPC) PasterCID(c context.Context, a *struct{}, res *map[int64]int64) (err error) {
  112. *res, err = r.s.PasterCID(c)
  113. return
  114. }