middleware

package
v0.0.0-...-5d187b5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package middleware populates request context and normalizes errors at the two edges OpenPay serves: the gRPC server and the grpc-gateway HTTP mux.

Both edges exist because the HTTP path registers the service in-process (RegisterOpenPayHandlerServer), which bypasses gRPC interceptors entirely. Anything that must apply to every request therefore needs an implementation on each side; keeping them in one package is what stops them drifting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallerMiddleware

func CallerMiddleware(authenticator Authenticator) runtime.Middleware

CallerMiddleware authenticates and populates the caller for requests arriving over HTTP.

It reads the raw headers rather than gRPC metadata because gateway middlewares run before the request is annotated, and it echoes the request id back so a caller can quote it in a support ticket.

func CallerUnaryInterceptor

func CallerUnaryInterceptor(authenticator Authenticator) grpc.UnaryServerInterceptor

CallerUnaryInterceptor authenticates and populates the caller for gRPC requests.

func ErrorHandler

func ErrorHandler(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error)

ErrorHandler renders errors as {code, message, request_id} instead of the gateway's default {code: <number>, message, details}. A numeric gRPC code is not a useful contract for a client; a stable string is.

func ErrorUnaryInterceptor

func ErrorUnaryInterceptor() grpc.UnaryServerInterceptor

ErrorUnaryInterceptor logs the full detail of a failure and returns the caller-safe form. Internal errors keep their SQL and driver text in the logs and send a generic message on the wire (apperrors.Error.Message).

func IncomingHeaderMatcher

func IncomingHeaderMatcher(key string) (string, bool)

IncomingHeaderMatcher forwards OpenPay's headers and otherwise defers to the gateway's default behaviour.

func OutgoingHeaderMatcher

func OutgoingHeaderMatcher(key string) (string, bool)

OutgoingHeaderMatcher sends response metadata a browser must see as a real header (an export's file name) under its own name, and everything else the gateway's default way, prefixed Grpc-Metadata-.

func RateLimitMiddleware

func RateLimitMiddleware(limiter RateLimiter) runtime.Middleware

RateLimitMiddleware is the HTTP twin of RateLimitUnaryInterceptor, and must likewise come after CallerMiddleware.

func RateLimitUnaryInterceptor

func RateLimitUnaryInterceptor(limiter RateLimiter) grpc.UnaryServerInterceptor

RateLimitUnaryInterceptor refuses gRPC requests over the caller's limit. It must run after CallerUnaryInterceptor: the limit is per credential, so it needs to know whose request this is.

func TraceMiddleLayer

func TraceMiddleLayer(ctx context.Context, msg string, fields *logger.Fields) (context.Context, string, *logger.Fields)

TraceMiddleLayer adds trace_id and span_id to every log line emitted inside a span. Without it, traces and logs are two separate investigations: you can see a request was slow, or read what it logged, but not join them.

Register it alongside logger.RequestMiddleLayer at startup.

Types

type Authenticator

type Authenticator interface {
	Authenticate(ctx context.Context, get func(key string) string) (appcontext.Caller, error)
}

Authenticator resolves a caller from request headers.

type RateLimiter

type RateLimiter interface {
	Allow(caller appcontext.Caller) error
}

RateLimiter decides whether an authenticated caller may proceed.

Jump to

Keyboard shortcuts

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