middleware

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthFromContext

func AuthFromContext(ctx context.Context) *model.AuthContext

AuthFromContext extracts the AuthContext from ctx. Returns nil if not set.

func WithAuthContext

func WithAuthContext(ctx context.Context, ac *model.AuthContext) context.Context

WithAuthContext sets the AuthContext in ctx. Used by handlers and tests.

Types

type APIKeyLookup

type APIKeyLookup interface {
	GetByPlaintext(ctx context.Context, plaintext string) (*model.APIKey, error)
	TouchLastUsed(ctx context.Context, id string) error
}

APIKeyLookup is the interface for looking up API keys by plaintext.

type Audit

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

Audit is the audit-logging middleware.

func NewAudit

func NewAudit(writer AuditWriter) *Audit

NewAudit creates an Audit middleware backed by the given writer.

func (*Audit) Handler

func (a *Audit) Handler(next http.Handler) http.Handler

Handler returns an http.Handler that appends an audit entry for each authenticated request. Requests with no auth context are passed through without logging.

type AuditWriter

type AuditWriter interface {
	Append(ctx context.Context, e *model.AuditEntry) error
}

AuditWriter can persist audit log entries.

type Auth

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

Auth is the authentication middleware.

func NewAuth

func NewAuth(clerk *ClerkVerifier, keys APIKeyLookup) *Auth

NewAuth creates a new Auth middleware.

func (*Auth) Handler

func (a *Auth) Handler(next http.Handler) http.Handler

Handler returns an http.Handler that authenticates requests via API key or Clerk JWT.

type ClerkVerifier

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

ClerkVerifier verifies Clerk JWTs by fetching and caching JWKS keys.

func NewClerkVerifier

func NewClerkVerifier(jwksURL string) *ClerkVerifier

NewClerkVerifier creates a ClerkVerifier that fetches keys from jwksURL.

func (*ClerkVerifier) Verify

func (v *ClerkVerifier) Verify(ctx context.Context, tokenString string) (*clerkClaims, error)

Verify parses and validates a JWT string, returning the claims on success.

type Quota

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

Quota is the request-quota enforcement middleware.

func NewQuota

func NewQuota(usage UsageCounter, tenants QuotaTenantLookup) *Quota

NewQuota creates a Quota middleware.

func (*Quota) Handler

func (q *Quota) Handler(next http.Handler) http.Handler

Handler returns an http.Handler that enforces per-tenant request quotas. Requests with no auth context are passed through without quota checks.

type QuotaTenantLookup

type QuotaTenantLookup interface {
	HasPaymentMethod(ctx context.Context, tenantID string) (bool, error)
}

QuotaTenantLookup checks whether a tenant has a payment method on file.

type UsageCounter

type UsageCounter interface {
	GetCurrentPeriodCount(ctx context.Context, tenantID string) (int64, error)
	IncrementRequestCount(ctx context.Context, tenantID, appID string) error
}

UsageCounter reads and increments request counts per tenant.

Jump to

Keyboard shortcuts

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