server.go 668 B

12345678910111213141516171819202122232425262728
  1. package grpc
  2. import (
  3. "context"
  4. "go-common/app/service/bbq/push/api/grpc/v1"
  5. "go-common/app/service/bbq/push/service"
  6. "go-common/library/net/rpc/warden"
  7. "google.golang.org/grpc"
  8. )
  9. //New 生成rpc服务
  10. func New(conf *warden.ServerConfig, srv *service.Service) (s *warden.Server, err error) {
  11. s = warden.NewServer(conf)
  12. s.Use(middleware())
  13. v1.RegisterPushServer(s.Server(), srv)
  14. _, err = s.Start()
  15. return
  16. }
  17. func middleware() grpc.UnaryServerInterceptor {
  18. return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
  19. //call chain
  20. resp, err = handler(ctx, req)
  21. return
  22. }
  23. }