transport

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 Imports: 16 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 transport is the common HTTP boundary. Business handlers remain in their module and perform resource-specific checks through their services.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthenticated = errors.New("authentication required")
	ErrForbidden       = errors.New("permission denied")
	ErrUnavailable     = errors.New("authorization unavailable")
)

Functions

func EnsureRequestID added in v0.2.1

func EnsureRequestID(w http.ResponseWriter, r *http.Request) (*http.Request, string, error)

EnsureRequestID reuses the active context request ID or generates a new one, ensuring X-Request-ID and X-Content-Type-Options headers are present.

func JSON

func JSON(w http.ResponseWriter, status int, value any)

func NewHandler

func NewHandler(registry *module.Registry, routes []Route, authn Authenticator, authz Authorizer, logger *slog.Logger) (handler http.Handler, err error)

NewHandler rejects ambiguous registrations and requires explicit public or protected access. An absent identity adapter never implies anonymous access.

func RequestID

func RequestID(ctx context.Context) string

func WithUnavailableCode added in v0.2.1

func WithUnavailableCode(handler http.Handler, code string) http.Handler

WithUnavailableCode preserves the handler's published 503 error code when module readiness prevents the router from calling the handler.

Types

type Access

type Access string
const (
	Public    Access = "public"
	Protected Access = "protected"
)

type Authenticator

type Authenticator interface {
	Authenticate(*http.Request) (Principal, error)
}

type Authorizer

type Authorizer interface {
	Authorize(context.Context, Principal, string, Resource) error
}

type Error

type Error = gen.Problem

type Principal

type Principal = account.Principal

func Identity

func Identity(ctx context.Context) (Principal, bool)

Identity is available only after the configured adapter authenticated a request.

type Resource

type Resource struct{ Type, ID string }

type Route

type Route struct {
	Method, Path, Module, Capability string
	Access                           Access
	Resource                         func(*http.Request) Resource
	Limiter                          *SourceLimiter
	Source                           func(*http.Request) string
	Handler                          http.Handler
}

type SourceLimiter added in v0.2.0

type SourceLimiter struct {
	Now        func() time.Time
	Limit      int
	Window     time.Duration
	MaxEntries int
	// contains filtered or unexported fields
}

SourceLimiter bounds anonymous reads per source within a fixed window. A full table rejects new sources in O(1) until the earliest entry expires.

func (*SourceLimiter) Allow added in v0.2.0

func (l *SourceLimiter) Allow(source string) bool

Jump to

Keyboard shortcuts

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