add grpc interceptor option (#987)

pull/990/head
Tony Chen 4 years ago committed by GitHub
parent 42b60381c9
commit 29e387a39c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      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 grpcOpts = []grpc.ServerOption{
grpc.ChainUnaryInterceptor(
var ints = []grpc.UnaryServerInterceptor{
srv.unaryServerInterceptor(),
),
}
if len(srv.ints) > 0 {
ints = append(ints, srv.ints...)
}
var grpcOpts = []grpc.ServerOption{
grpc.ChainUnaryInterceptor(ints...),
}
if len(srv.grpcOpts) > 0 {
grpcOpts = append(grpcOpts, srv.grpcOpts...)

Loading…
Cancel
Save