middleware

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 19 Imported by: ? 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 adapts the shared operation engine to HTTP.

Index

Constants

View Source
const (
	Critical   = operation.Critical
	Background = operation.Background
)
View Source
const CostHeader = "X-Gatewise-Cost"

Variables

View Source
var ErrInvalidCost = errors.New("gatewise: invalid operation metadata")
View Source
var ErrInvalidTenantIdentity = errors.New("gatewise: invalid tenant identity")
View Source
var ErrUntrustedCostSource = operation.ErrUntrustedCost
View Source
var ErrUntrustedTenantSource = errors.New("gatewise: untrusted tenant source")

Functions

func InjectCost added in v0.7.0

func InjectCost(r *http.Request)

InjectCost removes caller values and propagates only server-resolved metadata. The receiving ingress must trust this immediate peer and authenticate callers.

Types

type AdaptiveConfig

type AdaptiveConfig = operation.AdaptiveConfig

type ControllerState added in v0.2.0

type ControllerState = operation.ControllerState

type CostResolver added in v0.7.0

type CostResolver func(*http.Request) (decision.Cost, error)

CostResolver must derive logical write cost and keys from authenticated, validated operation plans. It must be local/fast and must not infer database cost from Content-Length. Use request context to avoid parsing bodies twice.

func TrustedCostHeader added in v0.7.0

func TrustedCostHeader(cidrs []string) (CostResolver, error)

TrustedCostHeader accepts only the fixed reserved wire header from explicitly trusted immediate peers. Ingress must authenticate and overwrite caller values.

type DecisionState added in v0.6.0

type DecisionState = operation.DecisionState

type HandlerOption

type HandlerOption func(*handlerOptions)

func WithLatencyTarget

func WithLatencyTarget(target time.Duration) HandlerOption

WithLatencyTarget gives this handler its own budget so naturally slower work is not compared directly to fast handlers sharing the same service capacity.

func WithResource added in v0.6.0

func WithResource(name string) HandlerOption

WithResource selects a server-controlled resource scope, never a caller header. Scoped ceilings still compare the shared Service in-flight count.

type OutcomeStatistics

type OutcomeStatistics = operation.OutcomeStatistics

type Priority

type Priority = operation.Priority

type PriorityStatistics

type PriorityStatistics = operation.PriorityStatistics

type QueueConfig added in v0.10.0

type QueueConfig = operation.QueueConfig

type ResolutionStatistics added in v0.4.0

type ResolutionStatistics = operation.ResolutionStatistics

type Service

type Service struct {
	*operation.Engine
	// contains filtered or unexported fields
}

func NewService

func NewService(c ServiceConfig) (*Service, error)

func (*Service) Middleware

func (s *Service) Middleware(priority Priority, next http.Handler, options ...HandlerOption) http.Handler

type ServiceConfig

type ServiceConfig struct {
	// QueueBodyMaxBytes defaults to 64KiB; -1 disables buffering. Larger/unknown bodies never wait.
	QueueBodyMaxBytes               int64
	Name                            string
	MaxConcurrent, ReservedCritical int
	Logger                          *slog.Logger
	Adaptive                        *AdaptiveConfig
	Tenants                         *TenantConfig
	Priorities                      *prioritypkg.Config
	Decisions                       *decision.Engine
	Queue                           *QueueConfig
	CostResolver                    CostResolver
}

type ServiceState

type ServiceState = operation.ServiceState

type Statistics

type Statistics = operation.Statistics

type TenantConfig added in v0.3.0

type TenantConfig struct {
	Sharing                       *TenantSharingConfig
	MaxConcurrent                 int
	Limits                        map[string]int // Optional overrides; copied and hashed at construction.
	MaxTracked                    int            // Default 1024 identified tenants, plus two bounded fallback buckets.
	IdleTTL                       time.Duration  // Default 5m; only inactive entries expire.
	MissingPolicy, OverflowPolicy TenantPolicy   // Default reject; shared uses a bounded bucket.
	Resolver                      TenantResolver
}

type TenantPolicy added in v0.3.0

type TenantPolicy = operation.TenantPolicy
const (
	TenantReject TenantPolicy = "reject"
	TenantShared TenantPolicy = "shared"
)

type TenantResolver added in v0.3.0

type TenantResolver func(*http.Request) (string, error)

TenantResolver must use an authenticated identity or explicitly trusted metadata. Empty identity invokes MissingPolicy. Errors reject without exposing their text. Keep resolvers local and fast; Gatewise does not authenticate identities.

func TrustedTenantHeader added in v0.3.0

func TrustedTenantHeader(header string, cidrs []string) (TenantResolver, error)

TrustedTenantHeader trusts only the immediate peer's address, never Forwarded or X-Forwarded-For. Trusted ingress must authenticate and overwrite the header. Requests without the header invoke MissingPolicy; supplied untrusted headers reject.

type TenantSharingConfig added in v0.5.0

type TenantSharingConfig = operation.TenantSharingConfig

TenantSharingConfig enables lending beyond configured tenant shares. The existing MaxConcurrent/Limits become target shares only when Sharing is set.

type TenantState added in v0.3.0

type TenantState = operation.TenantState

Jump to

Keyboard shortcuts

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