add unknown service handler
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
dda5d46e47
commit
b248593e35
14
grpc.go
14
grpc.go
@ -145,7 +145,7 @@ func (g *grpcServer) configure(opts ...server.Option) error {
|
||||
}
|
||||
|
||||
if opts := g.getGrpcOptions(); opts != nil {
|
||||
gopts = append(gopts, opts...)
|
||||
gopts = append(opts, gopts...)
|
||||
}
|
||||
|
||||
g.rsvc = nil
|
||||
@ -329,12 +329,22 @@ func (g *grpcServer) handler(srv interface{}, stream grpc.ServerStream) (err err
|
||||
*/
|
||||
|
||||
if svc == nil {
|
||||
if g.opts.Context != nil {
|
||||
if h, ok := g.opts.Context.Value(unknownServiceHandlerKey{}).(grpc.StreamHandler); ok {
|
||||
return h(srv, stream)
|
||||
}
|
||||
}
|
||||
return status.New(codes.Unimplemented, fmt.Sprintf("unknown service %s", serviceName)).Err()
|
||||
}
|
||||
|
||||
mtype := svc.method[methodName]
|
||||
if mtype == nil {
|
||||
return status.New(codes.Unimplemented, fmt.Sprintf("unknown service %s.%s", serviceName, methodName)).Err()
|
||||
if g.opts.Context != nil {
|
||||
if h, ok := g.opts.Context.Value(unknownServiceHandlerKey{}).(grpc.StreamHandler); ok {
|
||||
return h(srv, stream)
|
||||
}
|
||||
}
|
||||
return status.New(codes.Unimplemented, fmt.Sprintf("unknown service method %s.%s", serviceName, methodName)).Err()
|
||||
}
|
||||
|
||||
// process unary
|
||||
|
17
options.go
17
options.go
@ -9,10 +9,11 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
codecsKey struct{}
|
||||
grpcOptions struct{}
|
||||
maxMsgSizeKey struct{}
|
||||
reflectionKey struct{}
|
||||
codecsKey struct{}
|
||||
grpcOptions struct{}
|
||||
maxMsgSizeKey struct{}
|
||||
reflectionKey struct{}
|
||||
unknownServiceHandlerKey struct{}
|
||||
)
|
||||
|
||||
// gRPC Codec to be used to encode/decode requests for a given content type
|
||||
@ -37,8 +38,7 @@ func Options(opts ...grpc.ServerOption) server.Option {
|
||||
|
||||
//
|
||||
// MaxMsgSize set the maximum message in bytes the server can receive and
|
||||
// send. Default maximum message size is 4 MB.
|
||||
//
|
||||
// send. Default maximum message size is 4 MB.
|
||||
func MaxMsgSize(s int) server.Option {
|
||||
return server.SetOption(maxMsgSizeKey{}, s)
|
||||
}
|
||||
@ -47,3 +47,8 @@ func MaxMsgSize(s int) server.Option {
|
||||
func Reflection(b bool) server.Option {
|
||||
return server.SetOption(reflectionKey{}, b)
|
||||
}
|
||||
|
||||
// UnknownServiceHandler enables support for all services
|
||||
func UnknownServiceHandler(h grpc.StreamHandler) server.Option {
|
||||
return server.SetOption(unknownServiceHandlerKey{}, h)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user