hooks

package
v0.0.0-...-5352646 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

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

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

func UnregisterStreamHook(filter, name string) bool

UnregisterStreamHook unregisters the Stream hook with the specified filter and name and returns true on success.

func UnregisterUnaryHook

func UnregisterUnaryHook(filter, name string) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL