Documentation ¶
Overview ¶
Package interceptor provides commonly used grpc client-side and server-side interceptors.
Index ¶
- Variables
- func ClientCtxRequestID(ctx context.Context) string
- func ClientCtxRequestIDField(ctx context.Context) zap.Field
- func ClientTokenOption(appID string, appKey string, isSecure bool) grpc.DialOption
- func CtxRequestIDField(ctx context.Context) zap.Field
- func GetAuthCtxKey() string
- func GetAuthorization(token string) string
- func JwtVerify(ctx context.Context) (context.Context, error)
- func ServerCtxRequestID(ctx context.Context) string
- func ServerCtxRequestIDField(ctx context.Context) zap.Field
- func SetContextRequestIDKey(key string)
- func SetJwtTokenToCtx(ctx context.Context, authorization string) context.Context
- func StreamClientCircuitBreaker(opts ...CircuitBreakerOption) grpc.StreamClientInterceptor
- func StreamClientLog(logger *zap.Logger, opts ...LogOption) grpc.StreamClientInterceptor
- func StreamClientMetrics() grpc.StreamClientInterceptor
- func StreamClientRecovery() grpc.StreamClientInterceptor
- func StreamClientRequestID() grpc.StreamClientInterceptor
- func StreamClientRetry(opts ...RetryOption) grpc.StreamClientInterceptor
- func StreamClientTimeout(d time.Duration) grpc.StreamClientInterceptor
- func StreamClientTracing() grpc.StreamClientInterceptor
- func StreamServerCircuitBreaker(opts ...CircuitBreakerOption) grpc.StreamServerInterceptor
- func StreamServerJwtAuth(opts ...AuthOption) grpc.StreamServerInterceptor
- func StreamServerLog(logger *zap.Logger, opts ...LogOption) grpc.StreamServerInterceptor
- func StreamServerMetrics(opts ...metrics.Option) grpc.StreamServerInterceptor
- func StreamServerRateLimit(opts ...RatelimitOption) grpc.StreamServerInterceptor
- func StreamServerRecovery() grpc.StreamServerInterceptor
- func StreamServerRequestID() grpc.StreamServerInterceptor
- func StreamServerSimpleLog(logger *zap.Logger, opts ...LogOption) grpc.StreamServerInterceptor
- func StreamServerToken(f CheckToken) grpc.StreamServerInterceptor
- func StreamServerTracing() grpc.StreamServerInterceptor
- func UnaryClientCircuitBreaker(opts ...CircuitBreakerOption) grpc.UnaryClientInterceptor
- func UnaryClientLog(logger *zap.Logger, opts ...LogOption) grpc.UnaryClientInterceptor
- func UnaryClientMetrics() grpc.UnaryClientInterceptor
- func UnaryClientRecovery() grpc.UnaryClientInterceptor
- func UnaryClientRequestID() grpc.UnaryClientInterceptor
- func UnaryClientRetry(opts ...RetryOption) grpc.UnaryClientInterceptor
- func UnaryClientTimeout(d time.Duration) grpc.UnaryClientInterceptor
- func UnaryClientTracing() grpc.UnaryClientInterceptor
- func UnaryServerCircuitBreaker(opts ...CircuitBreakerOption) grpc.UnaryServerInterceptor
- func UnaryServerJwtAuth(opts ...AuthOption) grpc.UnaryServerInterceptor
- func UnaryServerLog(logger *zap.Logger, opts ...LogOption) grpc.UnaryServerInterceptor
- func UnaryServerMetrics(opts ...metrics.Option) grpc.UnaryServerInterceptor
- func UnaryServerRateLimit(opts ...RatelimitOption) grpc.UnaryServerInterceptor
- func UnaryServerRecovery() grpc.UnaryServerInterceptor
- func UnaryServerRequestID() grpc.UnaryServerInterceptor
- func UnaryServerSimpleLog(logger *zap.Logger, opts ...LogOption) grpc.UnaryServerInterceptor
- func UnaryServerToken(f CheckToken) grpc.UnaryServerInterceptor
- func UnaryServerTracing() grpc.UnaryServerInterceptor
- func WrapServerCtx(ctx context.Context, kvs ...KV) context.Context
- type AuthOption
- type AuthOptions
- type CheckToken
- type CircuitBreakerOption
- type CtxKeyString
- type KV
- type LogOption
- type RatelimitOption
- type RetryOption
Constants ¶
This section is empty.
Variables ¶
var (
// ContextRequestIDKey request id key for context
ContextRequestIDKey = "request_id"
)
var ErrLimitExceed = rl.ErrLimitExceed
ErrLimitExceed is returned when the rate limiter is triggered and the request is rejected due to limit exceeded.
var ErrNotAllowed = circuitbreaker.ErrNotAllowed
ErrNotAllowed error not allowed.
var RequestIDKey = CtxKeyString(ContextRequestIDKey)
RequestIDKey request_id
Functions ¶
func ClientCtxRequestID ¶
ClientCtxRequestID get request id from rpc client context.Context
func ClientCtxRequestIDField ¶
ClientCtxRequestIDField get request id field from rpc client context.Context
func ClientTokenOption ¶
func ClientTokenOption(appID string, appKey string, isSecure bool) grpc.DialOption
ClientTokenOption client token
func CtxRequestIDField ¶
CtxRequestIDField get request id field from context.Context
func GetAuthorization ¶
GetAuthorization combining tokens into authentication information
func JwtVerify ¶
JwtVerify get authorization from context to verify legitimacy, authorization composition format: authScheme token
func ServerCtxRequestID ¶
ServerCtxRequestID get request id from rpc server context.Context
func ServerCtxRequestIDField ¶
ServerCtxRequestIDField get request id field from rpc server context.Context
func SetContextRequestIDKey ¶
func SetContextRequestIDKey(key string)
SetContextRequestIDKey set context request id key
func SetJwtTokenToCtx ¶
SetJwtTokenToCtx set the token to the context in rpc client side Example:
ctx := SetJwtTokenToCtx(ctx, "Bearer jwt-token") cli.GetByID(ctx, req)
func StreamClientCircuitBreaker ¶
func StreamClientCircuitBreaker(opts ...CircuitBreakerOption) grpc.StreamClientInterceptor
StreamClientCircuitBreaker client-side stream circuit breaker interceptor
func StreamClientLog ¶
func StreamClientLog(logger *zap.Logger, opts ...LogOption) grpc.StreamClientInterceptor
StreamClientLog client log stream interceptor
func StreamClientMetrics ¶
func StreamClientMetrics() grpc.StreamClientInterceptor
StreamClientMetrics client-side metrics stream interceptor
func StreamClientRecovery ¶
func StreamClientRecovery() grpc.StreamClientInterceptor
StreamClientRecovery client-side recovery stream interceptor
func StreamClientRequestID ¶
func StreamClientRequestID() grpc.StreamClientInterceptor
StreamClientRequestID client request id stream interceptor
func StreamClientRetry ¶
func StreamClientRetry(opts ...RetryOption) grpc.StreamClientInterceptor
StreamClientRetry client-side retry stream interceptor
func StreamClientTimeout ¶
func StreamClientTimeout(d time.Duration) grpc.StreamClientInterceptor
StreamClientTimeout server-side timeout interceptor
func StreamClientTracing ¶
func StreamClientTracing() grpc.StreamClientInterceptor
StreamClientTracing client-side tracing stream interceptor
func StreamServerCircuitBreaker ¶
func StreamServerCircuitBreaker(opts ...CircuitBreakerOption) grpc.StreamServerInterceptor
StreamServerCircuitBreaker server-side stream circuit breaker interceptor
func StreamServerJwtAuth ¶
func StreamServerJwtAuth(opts ...AuthOption) grpc.StreamServerInterceptor
StreamServerJwtAuth jwt stream interceptor
func StreamServerLog ¶
func StreamServerLog(logger *zap.Logger, opts ...LogOption) grpc.StreamServerInterceptor
StreamServerLog Server-side log stream interceptor
func StreamServerMetrics ¶
func StreamServerMetrics(opts ...metrics.Option) grpc.StreamServerInterceptor
StreamServerMetrics server-side metrics stream interceptor
func StreamServerRateLimit ¶
func StreamServerRateLimit(opts ...RatelimitOption) grpc.StreamServerInterceptor
StreamServerRateLimit server-side stream circuit breaker interceptor
func StreamServerRecovery ¶
func StreamServerRecovery() grpc.StreamServerInterceptor
StreamServerRecovery recovery stream interceptor
func StreamServerRequestID ¶
func StreamServerRequestID() grpc.StreamServerInterceptor
StreamServerRequestID server-side request id stream interceptor
func StreamServerSimpleLog ¶
func StreamServerSimpleLog(logger *zap.Logger, opts ...LogOption) grpc.StreamServerInterceptor
StreamServerSimpleLog Server-side log stream interceptor, only print response
func StreamServerToken ¶
func StreamServerToken(f CheckToken) grpc.StreamServerInterceptor
StreamServerToken recovery stream token
func StreamServerTracing ¶
func StreamServerTracing() grpc.StreamServerInterceptor
StreamServerTracing server-side tracing stream interceptor
func UnaryClientCircuitBreaker ¶
func UnaryClientCircuitBreaker(opts ...CircuitBreakerOption) grpc.UnaryClientInterceptor
UnaryClientCircuitBreaker client-side unary circuit breaker interceptor
func UnaryClientLog ¶
func UnaryClientLog(logger *zap.Logger, opts ...LogOption) grpc.UnaryClientInterceptor
UnaryClientLog client log unary interceptor
func UnaryClientMetrics ¶
func UnaryClientMetrics() grpc.UnaryClientInterceptor
UnaryClientMetrics client-side metrics unary interceptor
func UnaryClientRecovery ¶
func UnaryClientRecovery() grpc.UnaryClientInterceptor
UnaryClientRecovery client-side unary recovery
func UnaryClientRequestID ¶
func UnaryClientRequestID() grpc.UnaryClientInterceptor
UnaryClientRequestID client-side request_id unary interceptor
func UnaryClientRetry ¶
func UnaryClientRetry(opts ...RetryOption) grpc.UnaryClientInterceptor
UnaryClientRetry client-side retry unary interceptor
func UnaryClientTimeout ¶
func UnaryClientTimeout(d time.Duration) grpc.UnaryClientInterceptor
UnaryClientTimeout client-side timeout unary interceptor
func UnaryClientTracing ¶
func UnaryClientTracing() grpc.UnaryClientInterceptor
UnaryClientTracing client-side tracing unary interceptor
func UnaryServerCircuitBreaker ¶
func UnaryServerCircuitBreaker(opts ...CircuitBreakerOption) grpc.UnaryServerInterceptor
UnaryServerCircuitBreaker server-side unary circuit breaker interceptor
func UnaryServerJwtAuth ¶
func UnaryServerJwtAuth(opts ...AuthOption) grpc.UnaryServerInterceptor
UnaryServerJwtAuth jwt unary interceptor
func UnaryServerLog ¶
func UnaryServerLog(logger *zap.Logger, opts ...LogOption) grpc.UnaryServerInterceptor
UnaryServerLog server-side log unary interceptor
func UnaryServerMetrics ¶
func UnaryServerMetrics(opts ...metrics.Option) grpc.UnaryServerInterceptor
UnaryServerMetrics server-side metrics unary interceptor
func UnaryServerRateLimit ¶
func UnaryServerRateLimit(opts ...RatelimitOption) grpc.UnaryServerInterceptor
UnaryServerRateLimit server-side unary circuit breaker interceptor
func UnaryServerRecovery ¶
func UnaryServerRecovery() grpc.UnaryServerInterceptor
UnaryServerRecovery recovery unary interceptor
func UnaryServerRequestID ¶
func UnaryServerRequestID() grpc.UnaryServerInterceptor
UnaryServerRequestID server-side request_id unary interceptor
func UnaryServerSimpleLog ¶
func UnaryServerSimpleLog(logger *zap.Logger, opts ...LogOption) grpc.UnaryServerInterceptor
UnaryServerSimpleLog server-side log unary interceptor, only print response
func UnaryServerToken ¶
func UnaryServerToken(f CheckToken) grpc.UnaryServerInterceptor
UnaryServerToken recovery unary token
func UnaryServerTracing ¶
func UnaryServerTracing() grpc.UnaryServerInterceptor
UnaryServerTracing server-side tracing unary interceptor
Types ¶
type AuthOption ¶
type AuthOption func(*AuthOptions)
AuthOption setting the Authentication Field
func WithAuthClaimsName ¶
func WithAuthClaimsName(claimsName string) AuthOption
WithAuthClaimsName set the key name of the information in ctx for authentication
func WithAuthIgnoreMethods ¶
func WithAuthIgnoreMethods(fullMethodNames ...string) AuthOption
WithAuthIgnoreMethods ways to ignore forensics fullMethodName format: /packageName.serviceName/methodName, example /api.userExample.v1.userExampleService/GetByID
func WithAuthScheme ¶
func WithAuthScheme(scheme string) AuthOption
WithAuthScheme set the message prefix for authentication
type AuthOptions ¶
type AuthOptions struct {
// contains filtered or unexported fields
}
AuthOptions settings
type CheckToken ¶
CheckToken check app id and app key Example:
var f CheckToken=func(appID string, appKey string) error{ if appID != targetAppID || appKey != targetAppKey { return status.Errorf(codes.Unauthenticated, "app id or app key checksum failure") } return nil }
type CircuitBreakerOption ¶
type CircuitBreakerOption func(*circuitBreakerOptions)
CircuitBreakerOption set the circuit breaker circuitBreakerOptions.
func WithGroup ¶
func WithGroup(g *group.Group) CircuitBreakerOption
WithGroup with circuit breaker group. NOTE: implements generics circuitbreaker.CircuitBreaker
func WithValidCode ¶
func WithValidCode(code ...codes.Code) CircuitBreakerOption
WithValidCode rpc code to mark failed
type LogOption ¶
type LogOption func(*logOptions)
LogOption log settings
func WithLogFields ¶
WithLogFields adding a custom print field
func WithLogIgnoreMethods ¶
WithLogIgnoreMethods ignore printing methods fullMethodName format: /packageName.serviceName/methodName, example /api.userExample.v1.userExampleService/GetByID
func WithReplaceGRPCLogger ¶
func WithReplaceGRPCLogger() LogOption
WithReplaceGRPCLogger replace grpc logger v2
type RatelimitOption ¶
type RatelimitOption func(*ratelimitOptions)
RatelimitOption set the rate limits ratelimitOptions.
func WithCPUQuota ¶
func WithCPUQuota(quota float64) RatelimitOption
WithCPUQuota with real cpu quota(if it can not collect from process correct);
func WithCPUThreshold ¶
func WithCPUThreshold(threshold int64) RatelimitOption
WithCPUThreshold with cpu threshold
type RetryOption ¶
type RetryOption func(*retryOptions)
RetryOption set the retry retryOptions.
func WithRetryErrCodes ¶
func WithRetryErrCodes(errCodes ...codes.Code) RetryOption
WithRetryErrCodes set the trigger retry error code
func WithRetryInterval ¶
func WithRetryInterval(t time.Duration) RetryOption
WithRetryInterval set the retry interval from 1 ms to 10 seconds
func WithRetryTimes ¶
func WithRetryTimes(n uint) RetryOption
WithRetryTimes set number of retries, max 10