Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultProxyOpt ¶
func DefaultProxyOpt(cc *grpc.ClientConn) grpc.ServerOption
DefaultProxyOpt returns an grpc.UnknownServiceHandler with a DefaultDirector.
func NewProxy ¶
func NewProxy(dst *grpc.ClientConn, opts ...grpc.ServerOption) *grpc.Server
NewProxy sets up a simple proxy that forwards all requests to dst.
func RegisterService ¶
func RegisterService(server *grpc.Server, director StreamDirector, serviceName string, methodNames ...string)
RegisterService sets up a proxy handler for a particular gRPC service and method. The behaviour is the same as if you were registering a handler method, e.g. from a generated pb.go file.
Types ¶
type StreamDirector ¶
type StreamDirector func(ctx context.Context, fullMethodName string) (context.Context, *grpc.ClientConn, error)
StreamDirector returns a gRPC ClientConn to be used to forward the call to.
The presence of the `Context` allows for rich filtering, e.g. based on Metadata (headers). If no handling is meant to be done, a `codes.NotImplemented` gRPC error should be returned.
The context returned from this function should be the context for the *outgoing* (to backend) call. In case you want to forward any Metadata between the inbound request and outbound requests, you should do it manually. However, you *must* propagate the cancel function (`context.WithCancel`) of the inbound context to the one returned.
It is worth noting that the StreamDirector will be fired *after* all server-side stream interceptors are invoked. So decisions around authorization, monitoring etc. are better to be handled there.
See the rather rich example.
func DefaultDirector ¶
func DefaultDirector(cc *grpc.ClientConn) StreamDirector
DefaultDirector returns a very simple forwarding StreamDirector that forwards all calls.