middleware

package
v0.108.4 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggingInterceptor added in v0.108.4

func LoggingInterceptor(l *zerolog.Logger) connect.Interceptor

LoggingInterceptor logs the start and finish of every call. The messages, field names and levels are a contract with log queries and alerts: grpc.code carries the canonical gRPC code name and grpc.error the gRPC rendering of the error.

func NewRequestGate added in v0.108.4

func NewRequestGate(authn *GRPCAuthN, limiter *HatchetRateLimiter, l *zerolog.Logger) connect.RequestGateFunc

NewRequestGate authenticates a call and applies the per-token rate limit once the request headers are in, before any message is read or decoded. A rejected call never reaches the interceptor chain, so the gate logs and traces it the way the chain would have.

func NewTelemetryInterceptor added in v0.108.4

func NewTelemetryInterceptor() connect.Interceptor

NewTelemetryInterceptor traces and times every unary and streaming call. It continues the caller's trace, and it must be the outermost interceptor so that the span covers the rest of the chain and records the error the client receives.

func RecoveryInterceptor added in v0.108.4

func RecoveryInterceptor(a errors.Alerter, l *zerolog.Logger) connect.Interceptor

RecoveryInterceptor converts a panic in a handler into an internal error, for unary and streaming calls.

Types

type ErrorInterceptor

type ErrorInterceptor struct {
	// contains filtered or unexported fields
}

func NewErrorInterceptor

func NewErrorInterceptor(a errors.Alerter,
	l *zerolog.Logger) *ErrorInterceptor

func (*ErrorInterceptor) Interceptor added in v0.108.4

func (e *ErrorInterceptor) Interceptor() connect.Interceptor

Interceptor converts errors without a code into internal errors, for unary and streaming calls.

type GRPCAuthN

type GRPCAuthN struct {
	// contains filtered or unexported fields
}

func NewAuthN

func NewAuthN(config *server.ServerConfig) *GRPCAuthN

func (*GRPCAuthN) Middleware

func (a *GRPCAuthN) Middleware(ctx context.Context, header http.Header) (context.Context, error)

Middleware validates the bearer token in header and returns ctx carrying the tenant, the token id and the call source. It runs from the request gate, before any message is read.

type HatchetApiTokenRateLimiter

type HatchetApiTokenRateLimiter struct {
	// contains filtered or unexported fields
}

type HatchetRateLimiter

type HatchetRateLimiter struct {
	// contains filtered or unexported fields
}

func NewHatchetRateLimiter

func NewHatchetRateLimiter(r rate.Limit, b int, l *zerolog.Logger) *HatchetRateLimiter

func (*HatchetRateLimiter) GetOrCreateTenantRateLimiter

func (rl *HatchetRateLimiter) GetOrCreateTenantRateLimiter(rateLimitToken string) *HatchetApiTokenRateLimiter

func (*HatchetRateLimiter) Limit

func (r *HatchetRateLimiter) Limit(ctx context.Context, procedure string) error

Limit is called before each request is processed. It should return an error if rate-limited. procedure is the full method name, for example /Dispatcher/Register.

Jump to

Keyboard shortcuts

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