server.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package server
  2. import (
  3. "context"
  4. item "go-common/app/service/openplatform/ticket-item/api/grpc/v1"
  5. "go-common/app/service/openplatform/ticket-item/conf"
  6. "go-common/app/service/openplatform/ticket-item/service"
  7. "go-common/library/log"
  8. "go-common/library/net/rpc/warden"
  9. "google.golang.org/grpc"
  10. )
  11. // New 新建warden实例
  12. func New(c *conf.Config) *warden.Server {
  13. //server := warden.NewServer(c.RPCServer)
  14. server := warden.NewServer(nil)
  15. server.Use(middleware())
  16. item.RegisterItemServer(server.Server(), service.New(c))
  17. item.RegisterGuestServer(server.Server(), service.New(c))
  18. item.RegisterBulletinServer(server.Server(), service.New(c))
  19. item.RegisterVenueServer(server.Server(), service.New(c))
  20. item.RegisterPlaceServer(server.Server(), service.New(c))
  21. item.RegisterAreaServer(server.Server(), service.New(c))
  22. item.RegisterSeatServer(server.Server(), service.New(c))
  23. /**go func() {
  24. err := server.Run(c.RPCServer.Addr)
  25. if err != nil {
  26. panic("run server failed!" + err.Error())
  27. }
  28. }()
  29. log.Info("warden run@%s", c.RPCServer.Addr)
  30. **/
  31. _, err := server.Start()
  32. if err != nil {
  33. panic("run server failed!" + err.Error())
  34. }
  35. return server
  36. }
  37. // 拦截器,作用类似于http中间件
  38. func middleware() grpc.UnaryServerInterceptor {
  39. return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
  40. // 记录调用方法
  41. log.Info("method:", info.FullMethod)
  42. // call chain
  43. resp, err = handler(ctx, req)
  44. return
  45. }
  46. }
  47. type server struct {
  48. is *service.ItemService
  49. }
  50. func (s *server) Info(ctx context.Context, in *item.InfoRequest) (*item.InfoReply, error) {
  51. return s.is.Info(ctx, in)
  52. }
  53. func (s *server) Cards(ctx context.Context, in *item.CardsRequest) (*item.CardsReply, error) {
  54. return s.is.Cards(ctx, in)
  55. }
  56. func (s *server) BillInfo(ctx context.Context, in *item.BillRequest) (*item.BillReply, error) {
  57. return s.is.BillInfo(ctx, in)
  58. }
  59. func (s *server) GuestInfo(ctx context.Context, in *item.GuestInfoRequest) (*item.GuestInfoReply, error) {
  60. return s.is.GuestInfo(ctx, in)
  61. }
  62. func (s *server) GuestStatus(ctx context.Context, in *item.GuestStatusRequest) (*item.GuestInfoReply, error) {
  63. return s.is.GuestStatus(ctx, in)
  64. }
  65. func (s *server) BulletinInfo(ctx context.Context, in *item.BulletinInfoRequest) (*item.BulletinReply, error) {
  66. return s.is.BulletinInfo(ctx, in)
  67. }
  68. func (s *server) BulletinCheck(ctx context.Context, in *item.BulletinCheckRequest) (*item.BulletinReply, error) {
  69. return s.is.BulletinCheck(ctx, in)
  70. }
  71. func (s *server) BulletinState(ctx context.Context, in *item.BulletinStateRequest) (*item.BulletinReply, error) {
  72. return s.is.BulletinState(ctx, in)
  73. }
  74. func (s *server) Wish(ctx context.Context, in *item.WishRequest) (*item.WishReply, error) {
  75. return s.is.Wish(ctx, in)
  76. }
  77. func (s *server) Fav(ctx context.Context, in *item.FavRequest) (*item.FavReply, error) {
  78. return s.is.Fav(ctx, in)
  79. }
  80. // VenueInfo 添加/修改场馆信息
  81. func (s *server) VenueInfo(ctx context.Context, in *item.VenueInfoRequest) (*item.VenueInfoReply, error) {
  82. return s.is.VenueInfo(ctx, in)
  83. }
  84. // PlaceInfo 添加/修改场地信息
  85. func (s *server) PlaceInfo(ctx context.Context, in *item.PlaceInfoRequest) (*item.PlaceInfoReply, error) {
  86. return s.is.PlaceInfo(ctx, in)
  87. }
  88. // AreaInfo 添加/修改区域信息
  89. func (s *server) AreaInfo(ctx context.Context, in *item.AreaInfoRequest) (*item.AreaInfoReply, error) {
  90. return s.is.AreaInfo(ctx, in)
  91. }
  92. // DeleteArea 删除区域信息
  93. func (s *server) DeleteArea(ctx context.Context, in *item.DeleteAreaRequest) (*item.DeleteAreaReply, error) {
  94. return s.is.DeleteArea(ctx, in)
  95. }
  96. // SeatInfo 添加/修改座位信息
  97. func (s *server) SeatInfo(ctx context.Context, in *item.SeatInfoRequest) (*item.SeatInfoReply, error) {
  98. return s.is.SeatInfo(ctx, in)
  99. }
  100. // SeatStock 设置座位库存
  101. func (s *server) SeatStock(ctx context.Context, in *item.SeatStockRequest) (*item.SeatStockReply, error) {
  102. return s.is.SeatStock(ctx, in)
  103. }
  104. // RemoveSeatOrders 删除坐票票价下所有座位
  105. func (s *server) RemoveSeatOrders(ctx context.Context, in *item.RemoveSeatOrdersRequest) (*item.RemoveSeatOrdersReply, error) {
  106. return s.is.RemoveSeatOrders(ctx, in)
  107. }
  108. // Version 添加/修改项目信息
  109. func (s *server) Version(ctx context.Context, in *item.VersionRequest) (*item.VersionReply, error) {
  110. return s.is.Version(ctx, in)
  111. }