contract

package
v2.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler func(
	runtime runtimecontract.Runtime,
	writer nethttp.ResponseWriter,
	request Request,
	err error,
) Response

type ForwardedHeadersPolicy

type ForwardedHeadersPolicy struct {
	TrustForwardedHeaders bool
	TrustedProxyList      []string
}

ForwardedHeadersPolicy decides whether forwarded headers from the direct peer are believed. The doors that accept it — Kernel.SetForwardedHeadersPolicy, the forwarded client-ip resolver — copy TrustedProxyList rather than retain the caller's slice, so the trust decision every request reads cannot be rewritten from outside after the hand-over. X-Forwarded-Proto is honoured by its leftmost entry, which is only trustworthy when the trusted edge SETS the header, overwriting whatever the client sent; an edge that appends leaves the client's spelling leftmost and the client then chooses the scheme.

type Handler

type Handler func(
	runtimeInstance runtimecontract.Runtime,
	writer nethttp.ResponseWriter,
	request Request,
) (Response, error)

type Kernel

type Kernel interface {
	Use(middlewares ...Middleware)

	SetNotFoundHandler(handler Handler)

	SetErrorHandler(handler ErrorHandler)

	SetForwardedHeadersPolicy(policy ForwardedHeadersPolicy)

	SetSessionCookiePolicy(policy SessionCookiePolicy)

	SetMethodPolicy(policy MethodPolicy)

	ServeHttp(serviceContainer containercontract.Container) nethttp.Handler
}

type MatchResult

type MatchResult struct {
	Handler         Handler
	Params          map[string]string
	RouteAttributes map[string]any
}

type MethodPolicy added in v2.13.0

type MethodPolicy struct {
	HeadFallbackToGet bool
	AutomaticOptions  bool
}

MethodPolicy decides the two answers the kernel synthesizes for methods no route declares: whether a HEAD request is served by the route registered for GET, and whether an OPTIONS request the application did not route is answered by the kernel with the Allow header it computes. Both default to true, which is what the framework has always done. An api that must answer 405 to OPTIONS, or one that serves HEAD itself, turns the matching half off through Kernel.SetMethodPolicy — the policy lives on the contract beside its two siblings because that is what an application holds.

type Middleware

type Middleware func(next Handler) Handler

type RateLimiter

type RateLimiter interface {
	Allow(key string) bool

	Reset(key string)
}

type Request

type Request interface {
	HttpRequest() *nethttp.Request

	Param(name string) (string, bool)

	Params() map[string]string

	Query() bagcontract.ParameterBag

	Post() bagcontract.ParameterBag

	Attributes() bagcontract.ParameterBag

	Header(name string) string

	RouteName() string

	RoutePattern() string

	RuntimeInstance() runtimecontract.Runtime

	RequestContext() RequestContext
}

type RequestContext

type RequestContext interface {
	RequestId() string

	StartedAt() time.Time
}

type Response

type Response interface {
	StatusCode() int

	SetStatusCode(statusCode int)

	Headers() nethttp.Header

	SetHeaders(headers nethttp.Header)

	BodyReader() io.Reader

	SetBodyReader(reader io.Reader)
}

type RouteDefinition

type RouteDefinition interface {
	Name() string

	Pattern() string

	Methods() []string

	Host() string

	Schemes() []string

	Requirements() map[string]string

	Defaults() map[string]string

	Locales() []string

	Priority() int

	Attributes() map[string]any
}

type RouteGroup

type RouteGroup interface {
	RouteHandler

	WithNamePrefix(namePrefix string)

	WithRequirements(requirements map[string]string)

	WithDefaults(defaults map[string]string)
}

type RouteHandler

type RouteHandler interface {
	Handle(method string, pattern string, handler Handler)

	HandleNamed(name string, method string, pattern string, handler Handler)

	HandleController(method string, pattern string, controller any)

	HandleNamedController(name string, method string, pattern string, controller any)

	HandleWithOptions(pattern string, handler Handler, options RouteOptions)
}

type RouteOptions

type RouteOptions interface {
	Name() string

	SetName(name string)

	Methods() []string

	Host() string

	Schemes() []string

	Requirements() map[string]string

	SetRequirements(requirements map[string]string)

	Defaults() map[string]string

	SetDefaults(defaults map[string]string)

	Locales() []string

	Priority() int

	Attributes() map[string]any
}

type RouteRegistry

type RouteRegistry interface {
	RouteDefinitions() []RouteDefinition

	RouteDefinition(routeName string) (RouteDefinition, bool)

	RouteDefinitionForUrlGeneration(routeName string) (UrlGenerationRouteDefinition, bool)
}

type Router

type Router interface {
	RouteHandler

	RouteDefinitions() []RouteDefinition

	RouteDefinition(routeName string) (RouteDefinition, bool)

	Match(method string, path string, host string, scheme string) (*MatchResult, bool)

	Group(pathPrefix string) RouteGroup
}

type RuntimeRateLimiter added in v2.10.0

type RuntimeRateLimiter interface {
	RateLimiter

	AllowWithRuntime(runtimeInstance runtimecontract.Runtime, key string) (bool, error)
}

RuntimeRateLimiter is an optional widening of RateLimiter for shared-store limiters: AllowWithRuntime threads the request context to the store and reports store failures. The returned allowed value must already reflect the limiter's failure policy, so callers honor it even when an error is returned; the rate-limit middleware prefers this method when the configured limiter implements it.

type SessionCookiePolicy

type SessionCookiePolicy struct {
	Path     string
	Domain   string
	SameSite nethttp.SameSite
	Secure   SessionCookieSecurePolicy
}

type SessionCookieSecurePolicy added in v2.13.0

type SessionCookieSecurePolicy int

SessionCookieSecurePolicy decides the Secure attribute of the session cookie. The zero value derives it from the scheme the forwarded-headers policy resolved, so a policy that does not mention it behaves as the framework always has; SessionCookieSecureAlways forces it on for a deployment whose proxy terminates TLS and forwards plaintext without being trusted for X-Forwarded-Proto.

const (
	SessionCookieSecureFromScheme SessionCookieSecurePolicy = iota
	SessionCookieSecureAlways
	SessionCookieSecureNever
)

type UrlGenerationRouteDefinition

type UrlGenerationRouteDefinition interface {
	Pattern() string

	Defaults() map[string]string

	Requirements() map[string]*regexp.Regexp
}

type UrlGenerator

type UrlGenerator interface {
	GeneratePath(routeName string, params map[string]string) (string, error)

	GenerateUrl(routeName string, params map[string]string, queryParams map[string]string) (string, error)
}

Jump to

Keyboard shortcuts

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