Documentation ¶
Overview ¶
Package hooks implements a gRPC middleware that executes service and method hooks.
Register a hook for all methods in a service with filter /package.service or a specific method with filter /package.service/method. Registering a hook overwrites existing hooks with the same filter and name.
Hooks are executed in order of registration. Service hooks are executed before service method hooks.
Index ¶
- func RegisterStreamHook(filter, name string, f StreamHandlerMiddleware)
- func RegisterUnaryHook(filter, name string, f UnaryHandlerMiddleware)
- func StreamServerInterceptor() grpc.StreamServerInterceptor
- func UnaryServerInterceptor() grpc.UnaryServerInterceptor
- func UnregisterStreamHook(filter, name string) bool
- func UnregisterUnaryHook(filter, name string) bool
- type StreamHandlerMiddleware
- type UnaryHandlerMiddleware
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterStreamHook ¶
func RegisterStreamHook(filter, name string, f StreamHandlerMiddleware)
RegisterStreamHook registers a new hook with the specified filter and name.
func RegisterUnaryHook ¶
func RegisterUnaryHook(filter, name string, f UnaryHandlerMiddleware)
RegisterUnaryHook registers a new hook with the specified filter and name.
Example (Method) ¶
RegisterUnaryHook("/ttn.lorawan.v3.ExampleService/Get", "add-magic", func(h grpc.UnaryHandler) grpc.UnaryHandler { return func(ctx context.Context, req interface{}) (interface{}, error) { ctx = context.WithValue(ctx, "magic", 42) return h(ctx, req) } })
Output:
Example (Service) ¶
RegisterUnaryHook("/ttn.lorawan.v3.ExampleService", "add-magic", func(h grpc.UnaryHandler) grpc.UnaryHandler { return func(ctx context.Context, req interface{}) (interface{}, error) { ctx = context.WithValue(ctx, "magic", 42) return h(ctx, req) } })
Output:
func StreamServerInterceptor ¶
func StreamServerInterceptor() grpc.StreamServerInterceptor
StreamServerInterceptor returns a new stream server interceptor that executes registered hooks.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor() grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptor that executes registered hooks.
func UnregisterStreamHook ¶
UnregisterStreamHook unregisters the Stream hook with the specified filter and name and returns true on success.
func UnregisterUnaryHook ¶
UnregisterUnaryHook unregisters the unary hook with the specified filter and name and returns true on success.
Types ¶
type StreamHandlerMiddleware ¶
type StreamHandlerMiddleware func(grpc.StreamHandler) grpc.StreamHandler
StreamHandlerMiddleware wraps grpc.StreamHandler.
type UnaryHandlerMiddleware ¶
type UnaryHandlerMiddleware func(grpc.UnaryHandler) grpc.UnaryHandler
UnaryHandlerMiddleware wraps grpc.UnaryHandler.