autowire

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package autowire assembles Kernel's default middleware pipelines.

The package keeps transport setup boring: services opt into providers and resolvers, while Kernel fixes the middleware order consistently for HTTP and gRPC servers/clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client(opts ...ClientOption) []middleware.Middleware

Client builds Kernel's default client pipeline in this order:

custom before -> metadata -> timeout -> rate limit -> circuit breaker -> retry -> custom after

func Server

func Server(opts ...ServerOption) []middleware.Middleware

Server builds Kernel's default server pipeline in this order:

custom before -> timeout -> ctx inject -> metadata -> authn -> rate limit -> authz/audit -> custom after

Types

type ClientOption

type ClientOption func(*clientOptions)

ClientOption configures the default client middleware pipeline.

func WithCircuitBreaker

func WithCircuitBreaker() ClientOption

WithCircuitBreaker enables client-side circuit breaker middleware.

func WithCircuitBreakerFactory

func WithCircuitBreakerFactory(factory func() circuitbreaker.CircuitBreaker) ClientOption

WithCircuitBreakerFactory enables client-side circuit breaker middleware with a custom factory. Tests and demos can inject deterministic breakers.

func WithClientAfter

func WithClientAfter(m ...middleware.Middleware) ClientOption

WithClientAfter appends client middleware.

func WithClientBefore

func WithClientBefore(m ...middleware.Middleware) ClientOption

WithClientBefore prepends client middleware.

func WithClientMetadataPropagation

func WithClientMetadataPropagation(opts ...metamw.Option) ClientOption

WithClientMetadataPropagation enables outbound metadata propagation.

func WithClientRateLimitPolicy

func WithClientRateLimitPolicy(policy ratelimitx.Policy, provider ratelimitx.Provider, key RateLimitKeyFunc) ClientOption

WithClientRateLimitPolicy enables client-side outbound rate limiting.

func WithClientRequestInfoResolver

func WithClientRequestInfoResolver(resolver requestx.Resolver) ClientOption

WithClientRequestInfoResolver adds an outbound request metadata resolver.

func WithClientTimeout

func WithClientTimeout(d time.Duration) ClientOption

WithClientTimeout adds a per-downstream client timeout.

func WithRetry

func WithRetry(opts ...retry.Option) ClientOption

WithRetry enables client retries for retryable/transient errors.

type RateLimitKeyFunc

type RateLimitKeyFunc func(ctx context.Context, req any) string

RateLimitKeyFunc derives a limiter key from request context and payload.

type ServerOption

type ServerOption func(*serverOptions)

ServerOption configures the default server middleware pipeline.

func WithAccess

func WithAccess(guard accessx.Guard, resolver accessmw.Resolver) ServerOption

WithAccess enables authorization and audit middleware.

func WithAdmission

func WithAdmission(chain admissionx.Chain) ServerOption

WithAdmission enables Kubernetes-style mutating/validating admission before business logic.

func WithAfter

func WithAfter(m ...middleware.Middleware) ServerOption

WithAfter appends middleware after Kernel's default chain.

func WithAllowAnonymous

func WithAllowAnonymous(allow bool) ServerOption

WithAllowAnonymous enables anonymous requests in authn middleware.

func WithAuthn

func WithAuthn(authenticator rootauthn.Authenticator, opts ...authnmw.Option) ServerOption

WithAuthn enables authentication middleware and syncs the resulting principal into authn and contextx contexts. Extra authn middleware options are applied after autowire's first-class options.

func WithBefore

func WithBefore(m ...middleware.Middleware) ServerOption

WithBefore prepends middleware before Kernel's default chain. Use sparingly; recovery usually belongs here when it is not owned by the transport.

func WithContextInjection

func WithContextInjection(opts ...ctxinject.Option) ServerOption

WithContextInjection configures ctxinject.Server. Context injection is always enabled because later authn/authz/audit/logging stages depend on it.

func WithCredentialExtractor

func WithCredentialExtractor(extractor authnmw.CredentialExtractor) ServerOption

WithCredentialExtractor configures authn credential extraction.

func WithMetadataPropagation

func WithMetadataPropagation(opts ...metamw.Option) ServerOption

WithMetadataPropagation enables Kernel metadata extraction on the server side.

func WithRateLimit

func WithRateLimit(limiter oldratelimit.Limiter) ServerOption

WithRateLimit enables the legacy global server-side limiter. Prefer WithRateLimitPolicy for new services because it carries backend/scope semantics.

func WithRateLimitPolicy

func WithRateLimitPolicy(policy ratelimitx.Policy, provider ratelimitx.Provider, key RateLimitKeyFunc) ServerOption

WithRateLimitPolicy enables policy-driven server-side rate limiting.

func WithRequestInfoResolver

func WithRequestInfoResolver(resolver requestx.Resolver) ServerOption

WithRequestInfoResolver adds a request metadata resolver. Generated code should provide this from proto access policy.

func WithTimeout

func WithTimeout(d time.Duration) ServerOption

WithTimeout adds a server request timeout near the front of the chain.

Jump to

Keyboard shortcuts

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