Merge pull request #103 from unistack-org/wildcard
add unknown service handler
This commit is contained in:
commit
ce3da2c9fa
14
grpc.go
14
grpc.go
@ -145,7 +145,7 @@ func (g *grpcServer) configure(opts ...server.Option) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if opts := g.getGrpcOptions(); opts != nil {
|
if opts := g.getGrpcOptions(); opts != nil {
|
||||||
gopts = append(gopts, opts...)
|
gopts = append(opts, gopts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
g.rsvc = nil
|
g.rsvc = nil
|
||||||
@ -329,12 +329,22 @@ func (g *grpcServer) handler(srv interface{}, stream grpc.ServerStream) (err err
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if svc == nil {
|
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()
|
return status.New(codes.Unimplemented, fmt.Sprintf("unknown service %s", serviceName)).Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
mtype := svc.method[methodName]
|
mtype := svc.method[methodName]
|
||||||
if mtype == nil {
|
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
|
// process unary
|
||||||
|
@ -13,6 +13,7 @@ type (
|
|||||||
grpcOptions struct{}
|
grpcOptions struct{}
|
||||||
maxMsgSizeKey struct{}
|
maxMsgSizeKey struct{}
|
||||||
reflectionKey struct{}
|
reflectionKey struct{}
|
||||||
|
unknownServiceHandlerKey struct{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// gRPC Codec to be used to encode/decode requests for a given content type
|
// gRPC Codec to be used to encode/decode requests for a given content type
|
||||||
@ -38,7 +39,6 @@ func Options(opts ...grpc.ServerOption) server.Option {
|
|||||||
//
|
//
|
||||||
// MaxMsgSize set the maximum message in bytes the server can receive and
|
// 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 {
|
func MaxMsgSize(s int) server.Option {
|
||||||
return server.SetOption(maxMsgSizeKey{}, s)
|
return server.SetOption(maxMsgSizeKey{}, s)
|
||||||
}
|
}
|
||||||
@ -47,3 +47,8 @@ func MaxMsgSize(s int) server.Option {
|
|||||||
func Reflection(b bool) server.Option {
|
func Reflection(b bool) server.Option {
|
||||||
return server.SetOption(reflectionKey{}, b)
|
return server.SetOption(reflectionKey{}, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnknownServiceHandler enables support for all services
|
||||||
|
func UnknownServiceHandler(h grpc.StreamHandler) server.Option {
|
||||||
|
return server.SetOption(unknownServiceHandlerKey{}, h)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user