transport

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 14 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 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

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 struct{ Issuer, Subject string }

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
	Handler                          http.Handler
}

type SourceLimiter added in v0.2.0

type SourceLimiter struct {
	Now func() time.Time
	// contains filtered or unexported fields
}

SourceLimiter bounds anonymous reads per source within a fixed window. A full table rejects new sources until expired entries can be reclaimed.

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