Skip to content

go-coldbrew/interceptors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc Go Report Card

interceptors

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.

Index

Variables

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.UnaryServerInterceptor

DebugLoggingInterceptor is the interceptor that logs all request/response from a handler

func DefaultClientInterceptor(defaultOpts ...interface{}) grpc.UnaryClientInterceptor

DefaultClientInterceptor are the set of default interceptors that should be applied to all client calls

func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInterceptor

DefaultClientInterceptors are the set of default interceptors that should be applied to all client calls

func DefaultClientStreamInterceptor(defaultOpts ...interface{}) grpc.StreamClientInterceptor

DefaultClientStreamInterceptor are the set of default interceptors that should be applied to all stream client calls

func DefaultClientStreamInterceptors(defaultOpts ...interface{}) []grpc.StreamClientInterceptor

DefaultClientStreamInterceptors are the set of default interceptors that should be applied to all stream client calls

func DefaultInterceptors() []grpc.UnaryServerInterceptor

DefaultInterceptors are the set of default interceptors that are applied to all coldbrew methods

func DefaultStreamInterceptors() []grpc.StreamServerInterceptor

DefaultStreamInterceptors are the set of default interceptors that should be applied to all coldbrew streams

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(ctx context.Context, fullMethodName string) bool

FilterMethodsFunc is the default implementation of Filter function

func GRPCClientInterceptor(options ...grpc_opentracing.Option) grpc.UnaryClientInterceptor

GRPCClientInterceptor is the interceptor that intercepts all cleint requests and adds tracing info to them

func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptor

HystrixClientInterceptor is the interceptor that intercepts all client requests and adds hystrix info to them

func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)

NRHttpTracer adds newrelic tracing to this http function

func NewRelicClientInterceptor() grpc.UnaryClientInterceptor

NewRelicClientInterceptor intercepts all client actions and reports them to newrelic

func NewRelicInterceptor() grpc.UnaryServerInterceptor

NewRelicInterceptor intercepts all server actions and reports them to newrelic

func OptionsInterceptor() grpc.UnaryServerInterceptor
func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor
func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor

ResponseTimeLoggingInterceptor logs response time for each request on server

func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor

ResponseTimeLoggingStreamInterceptor logs response time for stream RPCs.

func ServerErrorInterceptor() grpc.UnaryServerInterceptor

ServerErrorInterceptor intercepts all server actions and reports them to error notifier

func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor

ServerErrorStreamInterceptor intercepts server errors for stream RPCs and reports them to the error notifier.

func SetFilterFunc(ctx context.Context, ff FilterFunc)

SetFilterFunc sets the default filter function to be used by interceptors

func TraceIdInterceptor() grpc.UnaryServerInterceptor

TraceIdInterceptor 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

If it returns false, the given request will not be traced.

type FilterFunc func(ctx context.Context, fullMethodName string) bool

Generated by gomarkdoc