httpapi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package httpapi provides the HTTP transport and middleware adapters.

Index

Constants

View Source
const (
	// RequestIDHeader is the only request correlation header owned by the server.
	RequestIDHeader = "X-PowerContext-Request-ID"
	// SelectionDigestHeader and ReportDigestHeader carry canonical report identities.
	SelectionDigestHeader = "X-PowerContext-Selection-Digest"
	ReportDigestHeader    = "X-PowerContext-Report-Digest"
)

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(mapper ErrorMapper) v1.ErrorHandler

ErrorHandler returns the error adapter used by the generated server. Decode failures are deliberately normalized to FastAPI's 422 contract and raw error strings are never returned to clients.

func RequestID

func RequestID(ctx context.Context) (string, bool)

RequestID returns the server-owned identifier for the current ingress request. Caller-provided correlation headers are deliberately ignored.

func TracerProvider

func TracerProvider(provider trace.TracerProvider) trace.TracerProvider

TracerProvider wraps the provider passed to ogen so request IDs are bound as soon as ogen creates its ingress span. Unlike ogen middleware, this also runs for requests rejected during security or decoding.

func ValidateJSONUnicode

func ValidateJSONUnicode(next http.Handler) http.Handler

ValidateJSONUnicode rejects malformed UTF-8 and unpaired JSON surrogate escapes before Go's JSON decoder replaces them with U+FFFD. Pydantic rejects the same input at the Python transport boundary; preserving that distinction also prevents malformed private input from reaching application handlers.

func Wrap

func Wrap(next http.Handler, options Options) (http.Handler, error)

Wrap installs server-owned request IDs, optional static authentication and the feature gate for Handoff Report operations. It must wrap the complete HTTP mux so non-OpenAPI surfaces such as metrics and the Dashboard observe the same policy.

Types

type AccessLogOptions

type AccessLogOptions struct {
	Logger           *slog.Logger
	ResolveOperation func(*http.Request) string
	Skip             func(*http.Request) bool
}

type ApplicationError

type ApplicationError struct {
	StatusCode int
	Code       string
}

type ApplicationErrorClassifier

type ApplicationErrorClassifier func(error) ApplicationError

type Error

type Error struct {
	Code    string         `json:"code"`
	Message string         `json:"message"`
	Details map[string]any `json:"details"`
}

Error is the stable wire-level error detail. Details is encoded as JSON null when absent, matching the frozen Python envelope.

type ErrorMapper

type ErrorMapper func(error) (statusCode int, detail Error, ok bool)

ErrorMapper maps application/domain errors at the transport boundary. The bool is false when the mapper does not recognize an error.

type Middleware

type Middleware = middleware.Middleware

These aliases keep the request-ID middleware signature readable without introducing a transport abstraction parallel to ogen.

func LogApplicationFailures

func LogApplicationFailures(logger *slog.Logger, classify ApplicationErrorClassifier) Middleware

LogApplicationFailures records decoded application failures and cancellations. Successful operations are already represented by metrics and spans and intentionally remain silent, matching the frozen Python behavior.

func TraceApplication

func TraceApplication(provider trace.TracerProvider) Middleware

TraceApplication records the decoded application operation as a child of ogen's transport span. Decode/security failures therefore remain transport failures and never masquerade as entered application work.

type Next

type Next = middleware.Next

These aliases keep the request-ID middleware signature readable without introducing a transport abstraction parallel to ogen.

type Options

type Options struct {
	BearerToken         string
	HandoffReportRoutes bool
	Access              *AccessLogOptions
}

Options configures transport-only behavior around the generated server.

type Request

type Request = middleware.Request

These aliases keep the request-ID middleware signature readable without introducing a transport abstraction parallel to ogen.

type Response

type Response = middleware.Response

These aliases keep the request-ID middleware signature readable without introducing a transport abstraction parallel to ogen.

func BindSpanRequestID

func BindSpanRequestID(req Request, next Next) (Response, error)

BindSpanRequestID is an ogen middleware. ogen starts the ingress span before invoking middleware, so this is the first point where its final span ID is available. The outer response writer reads the same requestState when it commits headers.

func ValidatePowerContextContract

func ValidatePowerContextContract(request Request, next Next) (Response, error)

ValidatePowerContextContract supplements ogen's OpenAPI 3.0 validation with the few cross-field rules that the schema format cannot encode. Requests are rejected before application telemetry and endpoint dispatch; invalid responses are treated as server failures.

type Security

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

Security satisfies ogen's optional OpenAPI bearer scheme. Enforcement is performed by Wrap because authentication also covers metrics, MCP and the Dashboard; keeping this handler permissive when disabled preserves the contract's anonymous alternative.

func NewSecurity

func NewSecurity(token string) (*Security, error)

func (*Security) HandleBearerAuth

func (s *Security) HandleBearerAuth(ctx context.Context, _ v1.OperationName, auth v1.BearerAuth) (context.Context, error)

Jump to

Keyboard shortcuts

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