Documentation
¶
Index ¶
- type ErrorHandler
- type ForwardedHeadersPolicy
- type Handler
- type Kernel
- type MatchResult
- type MethodPolicy
- type Middleware
- type RateLimiter
- type Request
- type RequestContext
- type Response
- type RouteDefinition
- type RouteGroup
- type RouteHandler
- type RouteOptions
- type RouteRegistry
- type Router
- type RuntimeRateLimiter
- type SessionCookiePolicy
- type SessionCookieSecurePolicy
- type UrlGenerationRouteDefinition
- type UrlGenerator
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 ¶
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 MethodPolicy ¶ added in v1.19.0
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 RateLimiter ¶
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 RouteDefinition ¶
type RouteGroup ¶ added in v1.1.0
type RouteHandler ¶ added in v1.1.0
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 ¶ added in v1.1.0
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 v1.16.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 v1.19.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 )