diff --git a/transport/grpc/server.go b/transport/grpc/server.go index 2d3ddcc9f..61ef97904 100644 --- a/transport/grpc/server.go +++ b/transport/grpc/server.go @@ -61,6 +61,14 @@ func Middleware(m ...middleware.Middleware) ServerOption { } } +// UnaryInterceptor returns a ServerOption that sets the UnaryServerInterceptor for the +// server. +func UnaryInterceptor(in ...grpc.UnaryServerInterceptor) ServerOption { + return func(s *Server) { + s.ints = in + } +} + // Options with grpc options. func Options(opts ...grpc.ServerOption) ServerOption { return func(s *Server) { @@ -81,6 +89,7 @@ type Server struct { timeout time.Duration log *log.Helper middleware middleware.Middleware + ints []grpc.UnaryServerInterceptor grpcOpts []grpc.ServerOption health *health.Server metadata *metadata.Server @@ -101,10 +110,14 @@ func NewServer(opts ...ServerOption) *Server { for _, o := range opts { o(srv) } + var ints = []grpc.UnaryServerInterceptor{ + srv.unaryServerInterceptor(), + } + if len(srv.ints) > 0 { + ints = append(ints, srv.ints...) + } var grpcOpts = []grpc.ServerOption{ - grpc.ChainUnaryInterceptor( - srv.unaryServerInterceptor(), - ), + grpc.ChainUnaryInterceptor(ints...), } if len(srv.grpcOpts) > 0 { grpcOpts = append(grpcOpts, srv.grpcOpts...)