grpcmw

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2019 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientInterceptor

type ClientInterceptor interface {
	// AddGRPCUnaryInterceptor adds given unary interceptors to the chain.
	AddGRPCUnaryInterceptor(i ...grpc.UnaryClientInterceptor) ClientInterceptor
	// AddUnaryInterceptor is a convenient way for adding `UnaryClientInterceptor`
	// to the chain of unary interceptors.
	AddUnaryInterceptor(i ...UnaryClientInterceptor) ClientInterceptor
	// UnaryClientInterceptor returns the chain of unary interceptors.
	UnaryClientInterceptor() UnaryClientInterceptor
	// AddGRPCStreamInterceptor adds given stream interceptors to the chain.
	AddGRPCStreamInterceptor(i ...grpc.StreamClientInterceptor) ClientInterceptor
	// AddStreamInterceptor is a convenient way for adding
	// `StreamClientInterceptor` to the chain of stream interceptors.
	AddStreamInterceptor(i ...StreamClientInterceptor) ClientInterceptor
	// StreamClientInterceptor returns the chain of stream interceptors.
	StreamClientInterceptor() StreamClientInterceptor
	// Merge merges the given interceptors with the current interceptor.
	Merge(i ...ClientInterceptor) ClientInterceptor
	// Index returns the index of the `ClientInterceptor`.
	Index() string
}

ClientInterceptor represents a client interceptor that uses both `UnaryClientInterceptor` and `StreamClientInterceptor` and that can be indexed.

func NewClientInterceptor

func NewClientInterceptor(index string) ClientInterceptor

NewClientInterceptor initializes a new `ClientInterceptor` with `index` as its index. It initializes the underlying `UnaryClientInterceptor` and `StreamClientInterceptor`. This implementation is thread-safe.

type ClientInterceptorRegister

type ClientInterceptorRegister interface {
	ClientInterceptor
	// Register registers `level` at the index returned by its method `Index`.
	Register(level ClientInterceptor)
	// Get returns the `ClientInterceptor` registered at the index `key`. If
	// nothing is found, it returns (nil, false).
	Get(key string) (ClientInterceptor, bool)
}

ClientInterceptorRegister represents a register of `ClientInterceptor`, indexing them by using their method `Index`. It also implements `ClientInterceptor`.

func NewClientInterceptorRegister

func NewClientInterceptorRegister(index string) ClientInterceptorRegister

NewClientInterceptorRegister initializes a `ClientInterceptorRegister` with an empty register and `index` as index as its index. This implementation is thread-safe.

type ClientRouter

type ClientRouter interface {
	// GetRegister returns the interceptor register of the router.
	GetRegister() ClientInterceptorRegister
	// SetRegister sets the interceptor register of the router.
	SetRegister(reg ClientInterceptorRegister)
	// UnaryResolver returns a `grpc.UnaryClientInterceptor` that uses the
	// appropriate chain of interceptors with the given unary gRPC request.
	UnaryResolver() grpc.UnaryClientInterceptor
	// StreamResolver returns a `grpc.StreamClientInterceptor` that uses the
	// appropriate chain of interceptors with the given stream gRPC request.
	StreamResolver() grpc.StreamClientInterceptor
}

ClientRouter represents route resolver that allows to use the appropriate chain of interceptors for a given gRPC request with an interceptor register.

func NewClientRouter

func NewClientRouter() ClientRouter

NewClientRouter initializes a `ClientRouter`. This implementation is based on the official route format used by gRPC as defined here : https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md

Based on this format, this implementation splits the interceptors into four levels:

  • the global level: these are the interceptors called at each request.
  • the package level: these are the interceptors called at each request to a service from the corresponding package.
  • the service level: these are the interceptors called at each request to a method from the corresponding service.
  • the method level: these are the interceptors called at each request to the specific method.

type ServerInterceptor

type ServerInterceptor interface {
	// AddGRPCUnaryInterceptor adds given unary interceptors to the chain.
	AddGRPCUnaryInterceptor(i ...grpc.UnaryServerInterceptor) ServerInterceptor
	// AddUnaryInterceptor is a convenient way for adding `UnaryServerInterceptor`
	// to the chain of unary interceptors.
	AddUnaryInterceptor(i ...UnaryServerInterceptor) ServerInterceptor
	// UnaryServerInterceptor returns the chain of unary interceptors.
	UnaryServerInterceptor() UnaryServerInterceptor
	// AddGRPCStreamInterceptor adds given stream interceptors to the chain.
	AddGRPCStreamInterceptor(i ...grpc.StreamServerInterceptor) ServerInterceptor
	// AddStreamInterceptor is a convenient way for adding
	// `StreamServerInterceptor` to the chain of stream interceptors.
	AddStreamInterceptor(i ...StreamServerInterceptor) ServerInterceptor
	// StreamServerInterceptor returns the chain of stream interceptors.
	StreamServerInterceptor() StreamServerInterceptor
	// Merge merges the given interceptors with the current interceptor.
	Merge(interceptors ...ServerInterceptor) ServerInterceptor
	// Index returns the index of the `ServerInterceptor`.
	Index() string
}

ServerInterceptor represent a server interceptor that uses both `UnaryServerInterceptor` and `StreamServerInterceptor` and that can be indexed.

func NewServerInterceptor

func NewServerInterceptor(index string) ServerInterceptor

NewServerInterceptor initializes a new `ServerInterceptor` with `index` as its index. It initializes the underlying `UnaryServerInterceptor` and `StreamServerInterceptor`. This implementation is thread-safe.

type ServerInterceptorRegister

type ServerInterceptorRegister interface {
	ServerInterceptor
	// Register registers `level` at the index returned by its method `Index`.
	Register(level ServerInterceptor)
	// Get returns the `ServerInterceptor` registered at the index `key`. If
	// nothing is found, it returns (nil, false).
	Get(key string) (ServerInterceptor, bool)
}

ServerInterceptorRegister represents a register of `ServerInterceptor`, indexing them by using their method `Index`. It also implements `ServerInterceptor`.

func NewServerInterceptorRegister

func NewServerInterceptorRegister(index string) ServerInterceptorRegister

NewServerInterceptorRegister initializes a `ServerInterceptorRegister` with an empty register and `index` as index as its index. This implementation is thread-safe.

type ServerRouter

type ServerRouter interface {
	// GetRegister returns the interceptor register of the router.
	GetRegister() ServerInterceptorRegister
	// SetRegister sets the interceptor register of the router.
	SetRegister(reg ServerInterceptorRegister)
	// UnaryResolver returns a `grpc.UnaryServerInterceptor` that uses the
	// appropriate chain of interceptors with the given unary gRPC request.
	UnaryResolver() grpc.UnaryServerInterceptor
	// StreamResolver returns a `grpc.StreamServerInterceptor` that uses the
	// appropriate chain of interceptors with the given stream gRPC request.
	StreamResolver() grpc.StreamServerInterceptor
}

ServerRouter represents route resolver that allows to use the appropriate chain of interceptors for a given gRPC request with an interceptor register.

func NewServerRouter

func NewServerRouter() ServerRouter

NewServerRouter initializes a `ServerRouter`. This implementation is based on the official route format used by gRPC as defined here : https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md

Based on this format, this implementation splits the interceptors into four levels:

  • the global level: these are the interceptors called at each request.
  • the package level: these are the interceptors called at each request to a service from the corresponding package.
  • the service level: these are the interceptors called at each request to a method from the corresponding service.
  • the method level: these are the interceptors called at each request to the specific method.

type ServerStreamWrapper

type ServerStreamWrapper struct {
	grpc.ServerStream
	// contains filtered or unexported fields
}

ServerStreamWrapper represents a wrapper for `grpc.ServerStream` that allows to modify the context.

func WrapServerStream

func WrapServerStream(ss grpc.ServerStream) *ServerStreamWrapper

WrapServerStream returns checks if `ss` is already a `*ServerStreamWrapper`. If it is, it returns the `ss`, otherwise it returns a new wrapper for `grpc.ServerStream`.

func (ServerStreamWrapper) Context

func (w ServerStreamWrapper) Context() context.Context

Context returns the context of the wrapper0

func (*ServerStreamWrapper) SetContext

func (w *ServerStreamWrapper) SetContext(ctx context.Context)

SetContext set the context of the wrapper to `ctx`.

type StreamClientInterceptor

type StreamClientInterceptor interface {
	// Interceptor chains all added interceptors into a single
	// `grpc.StreamClientInterceptor`.
	Interceptor() grpc.StreamClientInterceptor
	// AddGRPCInterceptor adds given interceptors to the chain.
	AddGRPCInterceptor(i ...grpc.StreamClientInterceptor) StreamClientInterceptor
	// AddInterceptor is a convenient way for adding `StreamClientInterceptor`
	// to the chain of interceptors.
	AddInterceptor(i ...StreamClientInterceptor) StreamClientInterceptor
}

StreamClientInterceptor represents a client interceptor for gRPC methods that return a stream. It allows chaining of `grpc.StreamClientInterceptor` and other `StreamClientInterceptor`.

func NewStreamClientInterceptor

func NewStreamClientInterceptor(arr ...grpc.StreamClientInterceptor) StreamClientInterceptor

NewStreamClientInterceptor returns a new `StreamClientInterceptor`. It initializes its interceptor chain with `arr`. This implementation is thread-safe.

type StreamServerInterceptor

type StreamServerInterceptor interface {
	// Interceptor chains all added interceptors into a single
	// `grpc.StreamServerInterceptor`.
	Interceptor() grpc.StreamServerInterceptor
	// AddGRPCInterceptor adds given interceptors to the chain.
	AddGRPCInterceptor(i ...grpc.StreamServerInterceptor) StreamServerInterceptor
	// AddInterceptor is a convenient way for adding `StreamServerInterceptor`
	// to the chain of interceptors.
	AddInterceptor(i ...StreamServerInterceptor) StreamServerInterceptor
}

StreamServerInterceptor represents a server interceptor for gRPC methods that return a stream. It allows chaining of `grpc.StreamServerInterceptor` and other `StreamServerInterceptor`.

func NewStreamServerInterceptor

func NewStreamServerInterceptor(arr ...grpc.StreamServerInterceptor) StreamServerInterceptor

NewStreamServerInterceptor returns a new `StreamServerInterceptor`. It initializes its interceptor chain with `arr`. This implementation is thread-safe.

type UnaryClientInterceptor

type UnaryClientInterceptor interface {
	// Interceptor chains all added interceptors into a single
	// `grpc.UnaryClientInterceptor`.
	Interceptor() grpc.UnaryClientInterceptor
	// AddGRPCInterceptor adds `arr` to the chain of interceptors.
	AddGRPCInterceptor(i ...grpc.UnaryClientInterceptor) UnaryClientInterceptor
	// AddInterceptor is a convenient way for adding `UnaryClientInterceptor`
	// to the chain of interceptors.
	AddInterceptor(i ...UnaryClientInterceptor) UnaryClientInterceptor
}

UnaryClientInterceptor represents a client interceptor for gRPC methods that return a single value. It allows chaining of `grpc.UnaryClientInterceptor` and other `UnaryClientInterceptor`.

func NewUnaryClientInterceptor

func NewUnaryClientInterceptor(arr ...grpc.UnaryClientInterceptor) UnaryClientInterceptor

NewUnaryClientInterceptor returns a new `UnaryClientInterceptor`. It initializes its interceptor chain with `arr`. This implementation is thread-safe.

type UnaryServerInterceptor

type UnaryServerInterceptor interface {
	// Interceptor chains all added interceptors into a single
	// `grpc.UnaryServerInterceptor`.
	Interceptor() grpc.UnaryServerInterceptor
	// AddGRPCInterceptor adds given interceptors to the chain.
	AddGRPCInterceptor(i ...grpc.UnaryServerInterceptor) UnaryServerInterceptor
	// AddInterceptor is a convenient way for adding `UnaryServerInterceptor`
	// to the chain of interceptors.
	AddInterceptor(i ...UnaryServerInterceptor) UnaryServerInterceptor
}

UnaryServerInterceptor represents a server interceptor for gRPC methods that return a single value. It allows chaining of `grpc.UnaryServerInterceptor` and other `UnaryServerInterceptor`.

func NewUnaryServerInterceptor

func NewUnaryServerInterceptor(arr ...grpc.UnaryServerInterceptor) UnaryServerInterceptor

NewUnaryServerInterceptor returns a new `UnaryServerInterceptor`. It initializes its interceptor chain with `arr`. This implementation is thread-safe.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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