|
|
@ -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.
|
|
|
|
// Options with grpc options.
|
|
|
|
func Options(opts ...grpc.ServerOption) ServerOption { |
|
|
|
func Options(opts ...grpc.ServerOption) ServerOption { |
|
|
|
return func(s *Server) { |
|
|
|
return func(s *Server) { |
|
|
@ -81,6 +89,7 @@ type Server struct { |
|
|
|
timeout time.Duration |
|
|
|
timeout time.Duration |
|
|
|
log *log.Helper |
|
|
|
log *log.Helper |
|
|
|
middleware middleware.Middleware |
|
|
|
middleware middleware.Middleware |
|
|
|
|
|
|
|
ints []grpc.UnaryServerInterceptor |
|
|
|
grpcOpts []grpc.ServerOption |
|
|
|
grpcOpts []grpc.ServerOption |
|
|
|
health *health.Server |
|
|
|
health *health.Server |
|
|
|
metadata *metadata.Server |
|
|
|
metadata *metadata.Server |
|
|
@ -101,10 +110,14 @@ func NewServer(opts ...ServerOption) *Server { |
|
|
|
for _, o := range opts { |
|
|
|
for _, o := range opts { |
|
|
|
o(srv) |
|
|
|
o(srv) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var ints = []grpc.UnaryServerInterceptor{ |
|
|
|
|
|
|
|
srv.unaryServerInterceptor(), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if len(srv.ints) > 0 { |
|
|
|
|
|
|
|
ints = append(ints, srv.ints...) |
|
|
|
|
|
|
|
} |
|
|
|
var grpcOpts = []grpc.ServerOption{ |
|
|
|
var grpcOpts = []grpc.ServerOption{ |
|
|
|
grpc.ChainUnaryInterceptor( |
|
|
|
grpc.ChainUnaryInterceptor(ints...), |
|
|
|
srv.unaryServerInterceptor(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if len(srv.grpcOpts) > 0 { |
|
|
|
if len(srv.grpcOpts) > 0 { |
|
|
|
grpcOpts = append(grpcOpts, srv.grpcOpts...) |
|
|
|
grpcOpts = append(grpcOpts, srv.grpcOpts...) |
|
|
|