import "github.com/go-coldbrew/interceptors"Package interceptors provides a common set of interceptors which are used in Coldbrew
Almost all of these interceptors are reusable and can be used in any other project using grpc.
- Variables
- func AddStreamClientInterceptor(ctx context.Context, i ...grpc.StreamClientInterceptor)
- func AddStreamServerInterceptor(ctx context.Context, i ...grpc.StreamServerInterceptor)
- func AddUnaryClientInterceptor(ctx context.Context, i ...grpc.UnaryClientInterceptor)
- func AddUnaryServerInterceptor(ctx context.Context, i ...grpc.UnaryServerInterceptor)
- func DebugLoggingInterceptor() grpc.UnaryServerInterceptor
- func DefaultClientInterceptor(defaultOpts ...interface{}) grpc.UnaryClientInterceptor
- func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInterceptor
- func DefaultClientStreamInterceptor(defaultOpts ...interface{}) grpc.StreamClientInterceptor
- func DefaultClientStreamInterceptors(defaultOpts ...interface{}) []grpc.StreamClientInterceptor
- func DefaultInterceptors() []grpc.UnaryServerInterceptor
- func DefaultStreamInterceptors() []grpc.StreamServerInterceptor
- func DoHTTPtoGRPC(ctx context.Context, svr interface{}, handler func(ctx context.Context, req interface{}) (interface{}, error), in interface{}) (interface{}, error)
- func FilterMethodsFunc(ctx context.Context, fullMethodName string) bool
- func GRPCClientInterceptor(options ...grpc_opentracing.Option) grpc.UnaryClientInterceptor
- func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptor
- func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)
- func NewRelicClientInterceptor() grpc.UnaryClientInterceptor
- func NewRelicInterceptor() grpc.UnaryServerInterceptor
- func OptionsInterceptor() grpc.UnaryServerInterceptor
- func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor
- func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor
- func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor
- func ServerErrorInterceptor() grpc.UnaryServerInterceptor
- func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor
- func SetFilterFunc(ctx context.Context, ff FilterFunc)
- func TraceIdInterceptor() grpc.UnaryServerInterceptor
- func UseColdBrewClientInterceptors(ctx context.Context, flag bool)
- func UseColdBrewServerInterceptors(ctx context.Context, flag bool)
- type FilterFunc
var (
//FilterMethods is the list of methods that are filtered by default
FilterMethods = []string{"healthcheck", "readycheck", "serverreflectioninfo"}
)func AddStreamClientInterceptor(ctx context.Context, i ...grpc.StreamClientInterceptor)AddStreamClientInterceptor adds a server interceptor to default server interceptors
func AddStreamServerInterceptor(ctx context.Context, i ...grpc.StreamServerInterceptor)AddStreamServerInterceptor adds a server interceptor to default server interceptors
func AddUnaryClientInterceptor(ctx context.Context, i ...grpc.UnaryClientInterceptor)AddUnaryClientInterceptor adds a server interceptor to default server interceptors
func AddUnaryServerInterceptor(ctx context.Context, i ...grpc.UnaryServerInterceptor)AddUnaryServerInterceptor adds a server interceptor to default server interceptors
func DebugLoggingInterceptor() grpc.UnaryServerInterceptorDebugLoggingInterceptor is the interceptor that logs all request/response from a handler
func DefaultClientInterceptor(defaultOpts ...interface{}) grpc.UnaryClientInterceptorDefaultClientInterceptor are the set of default interceptors that should be applied to all client calls
func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInterceptorDefaultClientInterceptors are the set of default interceptors that should be applied to all client calls
func DefaultClientStreamInterceptor(defaultOpts ...interface{}) grpc.StreamClientInterceptorDefaultClientStreamInterceptor are the set of default interceptors that should be applied to all stream client calls
func DefaultClientStreamInterceptors(defaultOpts ...interface{}) []grpc.StreamClientInterceptorDefaultClientStreamInterceptors are the set of default interceptors that should be applied to all stream client calls
func DefaultInterceptors
func DefaultInterceptors() []grpc.UnaryServerInterceptorDefaultInterceptors are the set of default interceptors that are applied to all coldbrew methods
func DefaultStreamInterceptors() []grpc.StreamServerInterceptorDefaultStreamInterceptors are the set of default interceptors that should be applied to all coldbrew streams
func DoHTTPtoGRPC
func DoHTTPtoGRPC(ctx context.Context, svr interface{}, handler func(ctx context.Context, req interface{}) (interface{}, error), in interface{}) (interface{}, error)DoHTTPtoGRPC allows calling the interceptors when you use the Register<svc-name>HandlerServer in grpc-gateway, see example below for reference
func (s *svc) Echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return s.echo(ctx, req.(*proto.EchoRequest))
}
r, e := doHTTPtoGRPC(ctx, s, handler, req)
if e != nil {
return nil, e.(error)
}
return r.(*proto.EchoResponse), nil
}
func (s *svc) echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {
.... implementation ....
}
func FilterMethodsFunc
func FilterMethodsFunc(ctx context.Context, fullMethodName string) boolFilterMethodsFunc is the default implementation of Filter function
func GRPCClientInterceptor(options ...grpc_opentracing.Option) grpc.UnaryClientInterceptorGRPCClientInterceptor is the interceptor that intercepts all cleint requests and adds tracing info to them
func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptorHystrixClientInterceptor is the interceptor that intercepts all client requests and adds hystrix info to them
func NRHttpTracer
func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)NRHttpTracer adds newrelic tracing to this http function
func NewRelicClientInterceptor() grpc.UnaryClientInterceptorNewRelicClientInterceptor intercepts all client actions and reports them to newrelic
func NewRelicInterceptor
func NewRelicInterceptor() grpc.UnaryServerInterceptorNewRelicInterceptor intercepts all server actions and reports them to newrelic
func OptionsInterceptor
func OptionsInterceptor() grpc.UnaryServerInterceptorfunc PanicRecoveryInterceptor() grpc.UnaryServerInterceptorfunc ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptorResponseTimeLoggingInterceptor logs response time for each request on server
func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptorResponseTimeLoggingStreamInterceptor logs response time for stream RPCs.
func ServerErrorInterceptor() grpc.UnaryServerInterceptorServerErrorInterceptor intercepts all server actions and reports them to error notifier
func ServerErrorStreamInterceptor() grpc.StreamServerInterceptorServerErrorStreamInterceptor intercepts server errors for stream RPCs and reports them to the error notifier.
func SetFilterFunc
func SetFilterFunc(ctx context.Context, ff FilterFunc)SetFilterFunc sets the default filter function to be used by interceptors
func TraceIdInterceptor
func TraceIdInterceptor() grpc.UnaryServerInterceptorTraceIdInterceptor allows injecting trace id from request objects
func UseColdBrewClientInterceptors(ctx context.Context, flag bool)UseColdBrewClientInterceptors allows enabling/disabling coldbrew client interceptors
when set to false, the coldbrew client interceptors will not be used
func UseColdBrewServerInterceptors(ctx context.Context, flag bool)UseColdBrewServerInterceptors allows enabling/disabling coldbrew server interceptors
when set to false, the coldbrew server interceptors will not be used
type FilterFunc
If it returns false, the given request will not be traced.
type FilterFunc func(ctx context.Context, fullMethodName string) boolGenerated by gomarkdoc