http

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: 50 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConstraintAlphaLowercase = "^[a-z]+$"
	ConstraintAlpha          = "^[a-zA-Z]+$"
	ConstraintNumeric        = "^[0-9]+$"
	ConstraintAlphaNumeric   = "^[a-zA-Z0-9]+$"
)
View Source
const (
	EventHttpRequestProfile = "http.request.profile"

	KernelHttpProfilerListenerPriority = -900
)
View Source
const (
	RequestAttributeSession = "_session"
	RequestAttributeScheme  = "_scheme"
)
View Source
const (
	ContentTypeTextPlain = "text/plain; charset=utf-8"
	ContentTypeTextHtml  = "text/html; charset=utf-8"
	ContentTypeJson      = "application/json; charset=utf-8"
)
View Source
const (
	RouteAttributeName    = "_route"
	RouteAttributePattern = "_pattern"
	RouteAttributeMethods = "_methods"
	RouteAttributeHost    = "_host"
	RouteAttributeSchemes = "_schemes"
	RouteAttributeLocales = "_locales"
	RouteAttributeLocale  = "_locale"
)
View Source
const (
	BootCollisionKindHttpRoute     = "httpRoute"
	BootCollisionKindHttpRouteName = "httpRouteName"
)

the kinds a route collision is recorded under: one for two routes indistinguishable at dispatch, one for two distinct routes claiming the same name

View Source
const (
	ServiceRouteRegistry  = "service.http.route.registry"
	ServiceUrlGenerator   = "service.http.url.generator"
	ServiceRouter         = "service.http.router"
	ServiceRequestContext = "service.http.request.context"
)
View Source
const (
	HeaderRequestId = "X-Request-Id"
)
View Source
const (
	KernelExceptionListenerPriority = -1000
)
View Source
const (
	KernelResponseNormalizerListenerPriority = 100
)
View Source
const (
	KernelTerminateAccessLogListenerPriority = -100
)

Variables

This section is empty.

Functions

func BuildContentDisposition added in v2.5.0

func BuildContentDisposition(disposition string, filename string) string

func DeleteCookie

func DeleteCookie(response httpcontract.Response, name string, path string)

func ErrorJsonBodyHasExtraData

func ErrorJsonBodyHasExtraData() error

func ErrorUnsupportedContentType

func ErrorUnsupportedContentType() error

func JoinPaths

func JoinPaths(prefix string, pattern string) string

func NewRequirements

func NewRequirements(requirements ...Requirement) map[string]string

func NewRouteGroup

func NewRouteGroup(router httpcontract.Router, pathPrefix string) httpcontract.RouteGroup

func NewRouteOptions

func NewRouteOptions(
	name string,
	methods []string,
	host string,
	schemes []string,
	requirements map[string]string,
	defaults map[string]string,
	locales []string,
	priority int,
	attributes map[string]any,
) httpcontract.RouteOptions

func NormalizeResultToResponse

func NormalizeResultToResponse(
	runtimeInstance runtimecontract.Runtime,
	request httpcontract.Request,
	value any,
) (httpcontract.Response, error)

func PrefersHtml

func PrefersHtml(request httpcontract.Request) bool

func RecoverToError

func RecoverToError(recoveredValue any) error

func RegenerateRequestSession added in v2.13.0

func RegenerateRequestSession(request httpcontract.Request) (sessioncontract.Session, error)

RegenerateRequestSession rotates the id of the session the request carries and publishes the rotated session back on the request, which is the whole operation a login handler needs against session fixation: the response path saves that session and emits its cookie. Call it before writing the authenticated identity, and write the identity to the session it returns. The two steps are one call on purpose — rotating without republishing destroys the id the browser holds without ever telling it the new one.

func RegisterKernelExceptionListener

func RegisterKernelExceptionListener(eventDispatcher eventcontract.EventDispatcher, debugMode bool)

func RegisterKernelHttpProfilerListener

func RegisterKernelHttpProfilerListener(eventDispatcher eventcontract.EventDispatcher)

func RegisterKernelResponseNormalizerListener

func RegisterKernelResponseNormalizerListener(eventDispatcher eventcontract.EventDispatcher)

func RegisterKernelTerminateAccessLogListener

func RegisterKernelTerminateAccessLogListener(eventDispatcher eventcontract.EventDispatcher)

func RequestContextFromResolver added in v2.13.0

func RequestContextFromResolver(resolver containercontract.Resolver) httpcontract.RequestContext

RequestContextFromResolver is the error-tolerant form of RequestContextMustFromResolver, for code that runs on both process shapes and treats the request context as optional: absence — a console process, the root container — answers nil.

func RequestContextMustFromResolver added in v2.13.0

func RequestContextMustFromResolver(resolver containercontract.Resolver) httpcontract.RequestContext

RequestContextMustFromResolver resolves the current request's context — its id and start moment. Unlike its three siblings above, it takes a resolver rather than the container, because the service exists only on a request scope: the kernel installs it into the scope of each request, the root container never carries it, and a console process has application.ServiceProcessContext instead. A scoped provider hands its own resolver here; resolving from the container, or from a console process, panics with the service not registered.

func RouteRegistryMustFromContainer

func RouteRegistryMustFromContainer(serviceContainer containercontract.Container) httpcontract.RouteRegistry

func RouterMustFromContainer

func RouterMustFromContainer(serviceContainer containercontract.Container) httpcontract.Router

func SetCookie

func SetCookie(response httpcontract.Response, cookie *nethttp.Cookie)

func UrlGeneratorMustFromContainer

func UrlGeneratorMustFromContainer(serviceContainer containercontract.Container) httpcontract.UrlGenerator

func WrapResultHandler

func WrapResultHandler(resultHandler ResultHandler) httpcontract.Handler

func WriteToHttpResponseWriter

func WriteToHttpResponseWriter(
	runtimeInstance runtimecontract.Runtime,
	request httpcontract.Request,
	responseWriter nethttp.ResponseWriter,
	response httpcontract.Response,
) error

Types

type ErrorResponsePayload

type ErrorResponsePayload struct {
	Error string `json:"error"`
	Time  string `json:"time"`
}

func NewErrorResponsePayload

func NewErrorResponsePayload(message string, timeString string) *ErrorResponsePayload

type HttpRequestProfile

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

func NewHttpRequestProfile

func NewHttpRequestProfile(
	requestId string,
	method string,
	path string,
	routeName string,
	routePattern string,
	statusCode int,
	startedAt time.Time,
	finishedAt time.Time,
	duration time.Duration,
) *HttpRequestProfile

func (*HttpRequestProfile) Duration

func (instance *HttpRequestProfile) Duration() time.Duration

func (*HttpRequestProfile) FinishedAt

func (instance *HttpRequestProfile) FinishedAt() time.Time

func (*HttpRequestProfile) Method

func (instance *HttpRequestProfile) Method() string

func (*HttpRequestProfile) Path

func (instance *HttpRequestProfile) Path() string

func (*HttpRequestProfile) RequestId

func (instance *HttpRequestProfile) RequestId() string

func (*HttpRequestProfile) RouteName

func (instance *HttpRequestProfile) RouteName() string

func (*HttpRequestProfile) RoutePattern

func (instance *HttpRequestProfile) RoutePattern() string

func (*HttpRequestProfile) StartedAt

func (instance *HttpRequestProfile) StartedAt() time.Time

func (*HttpRequestProfile) StatusCode

func (instance *HttpRequestProfile) StatusCode() int

type Kernel

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

func NewKernel

func NewKernel(router httpcontract.Router) *Kernel

func (*Kernel) HasErrorHandler added in v2.13.0

func (instance *Kernel) HasErrorHandler() bool
HasErrorHandler reports whether the application installed an error handler; the composition root

reads it before deciding to register the framework exception listener.

func (*Kernel) OpenRequestScopes added in v2.13.0

func (instance *Kernel) OpenRequestScopes() int64

OpenRequestScopes reports how many request scopes are open right now: one per request being served, hijacked connections included, because the scope belongs to ServeHttp rather than to the connection. A shutdown reads it to tell a drained server from one that still has work inside it — net/http's own Shutdown cannot answer for a connection it has handed away.

func (*Kernel) ServeHttp

func (instance *Kernel) ServeHttp(serviceContainer containercontract.Container) nethttp.Handler

func (*Kernel) SetErrorHandler

func (instance *Kernel) SetErrorHandler(handler httpcontract.ErrorHandler)
SetErrorHandler installs the application's own error rendering, and it is read at boot: the

application registers the framework exception listener only when no handler is installed by then, because that listener answers every kernel.exception dispatch first and a handler behind it can never run. An installed handler therefore takes over what the listener did — negotiation, the request-id header, the validation errors payload — and when it returns nil the kernel's own default rendering answers instead.

func (*Kernel) SetForwardedHeadersPolicy

func (instance *Kernel) SetForwardedHeadersPolicy(policy httpcontract.ForwardedHeadersPolicy)

SetForwardedHeadersPolicy copies the trusted proxy list instead of retaining the caller's slice: every request's proxy-trust decision — whether X-Forwarded-Proto is believed, which sets the session cookie's Secure attribute — reads this list, and a caller reusing its slice after the call would rewrite the trust decision mid-serving, as an unsynchronized write racing every request goroutine. Every sibling configuration door copies its caller lists for the same reason.

func (*Kernel) SetMethodPolicy added in v2.13.0

func (instance *Kernel) SetMethodPolicy(policy httpcontract.MethodPolicy)

SetMethodPolicy installs the method policy the kernel reads on every request — whether HEAD falls back to the GET route, whether an unrouted OPTIONS is answered with the computed Allow header. Without this door the policy was a documented type with nowhere to hand it: DefaultKernelOptions built one, the kernel read one on every request, and no application could reach the field between them, so an api that had to answer 405 to OPTIONS wrote the configuration and watched it change nothing.

func (*Kernel) SetNotFoundHandler

func (instance *Kernel) SetNotFoundHandler(handler httpcontract.Handler)

func (*Kernel) SetSessionCookiePolicy

func (instance *Kernel) SetSessionCookiePolicy(policy httpcontract.SessionCookiePolicy)

func (*Kernel) Use

func (instance *Kernel) Use(middlewares ...httpcontract.Middleware)

Use appends middlewares to the chain the kernel builds around the matched handler. The chain decorates the handler path only: a response produced by an event listener — a security refusal, an error page — is dispatched through kernel.response and written before the chain is built, so cross-cutting response decoration belongs to kernel.response listeners; the cors package pairs its two doors that way.

type KernelControllerEvent

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

func NewKernelControllerEvent

func NewKernelControllerEvent(
	runtimeInstance runtimecontract.Runtime,
	request httpcontract.Request,
) *KernelControllerEvent

func (*KernelControllerEvent) Request

func (instance *KernelControllerEvent) Request() httpcontract.Request

func (*KernelControllerEvent) Response

func (instance *KernelControllerEvent) Response() httpcontract.Response

func (*KernelControllerEvent) Runtime

func (instance *KernelControllerEvent) Runtime() runtimecontract.Runtime

func (*KernelControllerEvent) SetResponse

func (instance *KernelControllerEvent) SetResponse(response httpcontract.Response)

type KernelExceptionEvent

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

func NewKernelExceptionEvent

func NewKernelExceptionEvent(
	runtimeInstance runtimecontract.Runtime,
	request httpcontract.Request,
	err error,
) *KernelExceptionEvent

func (*KernelExceptionEvent) Err

func (instance *KernelExceptionEvent) Err() error

func (*KernelExceptionEvent) Request

func (instance *KernelExceptionEvent) Request() httpcontract.Request

func (*KernelExceptionEvent) Response

func (instance *KernelExceptionEvent) Response() httpcontract.Response

func (*KernelExceptionEvent) Runtime

func (instance *KernelExceptionEvent) Runtime() runtimecontract.Runtime

func (*KernelExceptionEvent) SetResponse

func (instance *KernelExceptionEvent) SetResponse(response httpcontract.Response)

type KernelOptions

type KernelOptions struct {
	MethodPolicy           MethodPolicy
	ForwardedHeadersPolicy httpcontract.ForwardedHeadersPolicy
	SessionCookiePolicy    httpcontract.SessionCookiePolicy
}

func DefaultKernelOptions

func DefaultKernelOptions() KernelOptions

type KernelRequestEvent

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

func NewKernelRequestEvent

func NewKernelRequestEvent(
	runtimeInstance runtimecontract.Runtime,
	request httpcontract.Request,
) *KernelRequestEvent

func (*KernelRequestEvent) Request

func (instance *KernelRequestEvent) Request() httpcontract.Request

func (*KernelRequestEvent) Response

func (instance *KernelRequestEvent) Response() httpcontract.Response

func (*KernelRequestEvent) Runtime

func (instance *KernelRequestEvent) Runtime() runtimecontract.Runtime

func (*KernelRequestEvent) SetResponse

func (instance *KernelRequestEvent) SetResponse(response httpcontract.Response)

type KernelResponseEvent

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

func NewKernelResponseEvent

func NewKernelResponseEvent(request httpcontract.Request, response httpcontract.Response) *KernelResponseEvent

func (*KernelResponseEvent) Request

func (instance *KernelResponseEvent) Request() httpcontract.Request

func (*KernelResponseEvent) Response

func (instance *KernelResponseEvent) Response() httpcontract.Response

func (*KernelResponseEvent) SetResponse

func (instance *KernelResponseEvent) SetResponse(response httpcontract.Response)

type KernelTerminateEvent

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

func NewKernelTerminateEvent

func NewKernelTerminateEvent(
	runtimeInstance runtimecontract.Runtime,
	request httpcontract.Request,
	response httpcontract.Response,
) *KernelTerminateEvent

func (*KernelTerminateEvent) Request

func (instance *KernelTerminateEvent) Request() httpcontract.Request

func (*KernelTerminateEvent) Response

func (instance *KernelTerminateEvent) Response() httpcontract.Response

func (*KernelTerminateEvent) Runtime

func (instance *KernelTerminateEvent) Runtime() runtimecontract.Runtime

type MethodPolicy

type MethodPolicy = httpcontract.MethodPolicy

MethodPolicy is the contract's type under this package's name: the policy travels through httpcontract.Kernel.SetMethodPolicy, where an application meets the kernel, and the alias keeps every caller and every composite literal written against melodyhttp.MethodPolicy compiling unchanged.

type Request

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

func NewRequest

func NewRequest(
	httpRequest *nethttp.Request,
	routeParams map[string]string,
	runtimeInstance runtimecontract.Runtime,
	requestContext httpcontract.RequestContext,
) *Request

func (*Request) Attributes

func (instance *Request) Attributes() bagcontract.ParameterBag

func (*Request) BindJson

func (instance *Request) BindJson(target any) error

func (*Request) BindJsonAndValidate

func (instance *Request) BindJsonAndValidate(target any) error

func (*Request) ContentType

func (instance *Request) ContentType() string

func (*Request) Cookie

func (instance *Request) Cookie(name string) (*nethttp.Cookie, error)

func (*Request) Cookies

func (instance *Request) Cookies() []*nethttp.Cookie

func (*Request) FormValue

func (instance *Request) FormValue(key string) string

func (*Request) Header

func (instance *Request) Header(name string) string

func (*Request) HttpRequest

func (instance *Request) HttpRequest() *nethttp.Request

func (*Request) Input

func (instance *Request) Input(key string) string
Input answers the first value of a repeated key, as FormValue beside it and url.Values.Get already do.

The request bags keep a single key and a repeated one apart by type and bag.String refuses a slice with a panic — right where the key is the programmer's, wrong here, because the shape of a request parameter is the client's to choose: "?tag=a&tag=b" turned every handler reading a parameter by name into a 500 with a full stack record, unauthenticated and free to repeat. A handler that needs the whole array reads it with bag.StringSlice, which is what the panic was pointing at.

func (*Request) Locale

func (instance *Request) Locale() string

func (*Request) Method

func (instance *Request) Method() string

func (*Request) Param

func (instance *Request) Param(name string) (string, bool)

func (*Request) Params

func (instance *Request) Params() map[string]string

func (*Request) ParseFormBody

func (instance *Request) ParseFormBody() error

func (*Request) Path

func (instance *Request) Path() string

func (*Request) Post

func (instance *Request) Post() bagcontract.ParameterBag

func (*Request) Query

func (instance *Request) Query() bagcontract.ParameterBag

func (*Request) RequestContext

func (instance *Request) RequestContext() httpcontract.RequestContext

func (*Request) RouteName

func (instance *Request) RouteName() string

func (*Request) RoutePattern

func (instance *Request) RoutePattern() string

func (*Request) RuntimeInstance

func (instance *Request) RuntimeInstance() runtimecontract.Runtime

type RequestContext

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

func NewRequestContext

func NewRequestContext(requestId string, startedAt time.Time) *RequestContext

func (*RequestContext) RequestId

func (instance *RequestContext) RequestId() string

func (*RequestContext) StartedAt

func (instance *RequestContext) StartedAt() time.Time

type Requirement

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

func NewRequirement

func NewRequirement(parameterName string, pattern string) *Requirement

func RequireAlpha

func RequireAlpha(parameterName string) *Requirement

func RequireAlphaLowercase

func RequireAlphaLowercase(parameterName string) *Requirement

func RequireAlphaNumeric

func RequireAlphaNumeric(parameterName string) *Requirement

func RequireNumeric

func RequireNumeric(parameterName string) *Requirement

func (*Requirement) ParameterName

func (instance *Requirement) ParameterName() string

func (*Requirement) Pattern

func (instance *Requirement) Pattern() string

type Response

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

func AttachmentResponse

func AttachmentResponse(statusCode int, path string, filename string) (*Response, error)

func EmptyResponse

func EmptyResponse(statusCode int) *Response

func FileResponse

func FileResponse(statusCode int, path string) (*Response, error)
FileResponse opens path exactly as given and streams it as the response body — it applies no

folding, no root and no containment check, so it must never be handed a path built from client input without the caller confining it first. `os.Open("storage/invoices/" + request.Input("name"))` reads "../../../../etc/passwd" as readily as an invoice. Confine the name to a known directory before the call (reject "..", resolve symlinks and check the result stays under the root — the static file server does this for the paths it serves), or serve a fixed set of files by a lookup the client cannot steer. The returned body is the open file; the kernel closes it after the response is written.

func HtmlResponse

func HtmlResponse(statusCode int, html string) *Response

func JsonErrorResponse

func JsonErrorResponse(statusCode int, message string) *Response

func JsonResponse

func JsonResponse(statusCode int, payload any) (*Response, error)

func NewResponse

func NewResponse(statusCode int, body []byte) *Response

func RedirectFound

func RedirectFound(location string) *Response

func RedirectMovedPermanently

func RedirectMovedPermanently(location string) *Response

func RedirectResponse

func RedirectResponse(location string, statusCode int) *Response

func TextResponse

func TextResponse(statusCode int, message string) *Response

func (*Response) BodyReader

func (instance *Response) BodyReader() io.Reader

func (*Response) Close added in v2.2.4

func (instance *Response) Close() error

func (*Response) Headers

func (instance *Response) Headers() nethttp.Header

func (*Response) SetBodyReader

func (instance *Response) SetBodyReader(reader io.Reader)

func (*Response) SetHeaders

func (instance *Response) SetHeaders(headers nethttp.Header)

func (*Response) SetStatusCode

func (instance *Response) SetStatusCode(statusCode int)

func (*Response) StatusCode

func (instance *Response) StatusCode() int

type ResultHandler

type ResultHandler func(
	runtimeInstance runtimecontract.Runtime,
	writer nethttp.ResponseWriter,
	request httpcontract.Request,
) (any, error)

type RouteDefinition

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

func NewRouteDefinition

func NewRouteDefinition(
	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,
) *RouteDefinition

func (*RouteDefinition) Attributes

func (instance *RouteDefinition) Attributes() map[string]any

func (*RouteDefinition) Defaults

func (instance *RouteDefinition) Defaults() map[string]string

func (*RouteDefinition) Host

func (instance *RouteDefinition) Host() string

func (*RouteDefinition) Locales

func (instance *RouteDefinition) Locales() []string

func (*RouteDefinition) MarshalJSON

func (instance *RouteDefinition) MarshalJSON() ([]byte, error)

func (*RouteDefinition) Methods

func (instance *RouteDefinition) Methods() []string

func (*RouteDefinition) Name

func (instance *RouteDefinition) Name() string

func (*RouteDefinition) Pattern

func (instance *RouteDefinition) Pattern() string

func (*RouteDefinition) Priority

func (instance *RouteDefinition) Priority() int

func (*RouteDefinition) Requirements

func (instance *RouteDefinition) Requirements() map[string]string

func (*RouteDefinition) Schemes

func (instance *RouteDefinition) Schemes() []string

type RouteGroup

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

func (*RouteGroup) Handle

func (instance *RouteGroup) Handle(method string, pattern string, handler httpcontract.Handler)

func (*RouteGroup) HandleController

func (instance *RouteGroup) HandleController(
	method string,
	pattern string,
	controller any,
)

func (*RouteGroup) HandleNamed

func (instance *RouteGroup) HandleNamed(name string, method string, pattern string, handler httpcontract.Handler)

func (*RouteGroup) HandleNamedController

func (instance *RouteGroup) HandleNamedController(
	name string,
	method string,
	pattern string,
	controller any,
)

func (*RouteGroup) HandleWithOptions

func (instance *RouteGroup) HandleWithOptions(pattern string, handler httpcontract.Handler, options httpcontract.RouteOptions)

func (*RouteGroup) WithDefaults

func (instance *RouteGroup) WithDefaults(defaults map[string]string)

func (*RouteGroup) WithNamePrefix

func (instance *RouteGroup) WithNamePrefix(namePrefix string)

func (*RouteGroup) WithRequirements

func (instance *RouteGroup) WithRequirements(requirements map[string]string)

type RouteOptions

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

func (*RouteOptions) Attributes

func (instance *RouteOptions) Attributes() map[string]any

func (*RouteOptions) Defaults

func (instance *RouteOptions) Defaults() map[string]string

func (*RouteOptions) Host

func (instance *RouteOptions) Host() string

func (*RouteOptions) Locales

func (instance *RouteOptions) Locales() []string

func (*RouteOptions) Methods

func (instance *RouteOptions) Methods() []string

func (*RouteOptions) Name

func (instance *RouteOptions) Name() string

func (*RouteOptions) Priority

func (instance *RouteOptions) Priority() int

func (*RouteOptions) Requirements

func (instance *RouteOptions) Requirements() map[string]string

func (*RouteOptions) Schemes

func (instance *RouteOptions) Schemes() []string

func (*RouteOptions) SetDefaults

func (instance *RouteOptions) SetDefaults(defaults map[string]string)

func (*RouteOptions) SetName

func (instance *RouteOptions) SetName(name string)

func (*RouteOptions) SetRequirements

func (instance *RouteOptions) SetRequirements(requirements map[string]string)

type RouteRegistry

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

func NewRouteRegistry

func NewRouteRegistry() *RouteRegistry

func (*RouteRegistry) RouteDefinition

func (instance *RouteRegistry) RouteDefinition(routeName string) (httpcontract.RouteDefinition, bool)

func (*RouteRegistry) RouteDefinitionForUrlGeneration

func (instance *RouteRegistry) RouteDefinitionForUrlGeneration(routeName string) (httpcontract.UrlGenerationRouteDefinition, bool)

func (*RouteRegistry) RouteDefinitions

func (instance *RouteRegistry) RouteDefinitions() []httpcontract.RouteDefinition

func (*RouteRegistry) SetBootCollisionRecorder added in v2.13.0

func (instance *RouteRegistry) SetBootCollisionRecorder(recorder func(kind string, name string))

SetBootCollisionRecorder arms the aggregated collision channel: with a recorder set, registerRoute records a duplicate — the first registration wins — instead of panicking over each one in isolation, so a boot collects every collision into the one report that names them all. A nil recorder disarms the channel and restores the immediate refusal.

type Router

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

func NewRouter

func NewRouter() *Router

func NewRouterWithRouteRegistry

func NewRouterWithRouteRegistry(routeRegistry *RouteRegistry) *Router

func (*Router) AllowedMethods

func (instance *Router) AllowedMethods(path string, host string, scheme string) []string

AllowedMethods gathers the methods every route matching this path, host and scheme accepts — the four filters the matcher itself applies, locales included: a route restricted to a set of locales does not accept a request whose path carries another one, so announcing its methods advertised a route the matcher refuses to reach. What this answers is the routing table's own set; the kernel adds the synthetic OPTIONS and HEAD its MethodPolicy allows on top of it when it writes an Allow header, so a caller building that header itself gets the routes but not the synthetic entries.

func (*Router) Group

func (instance *Router) Group(pathPrefix string) httpcontract.RouteGroup

func (*Router) Handle

func (instance *Router) Handle(method string, pattern string, handler httpcontract.Handler)

func (*Router) HandleController

func (instance *Router) HandleController(
	method string,
	pattern string,
	controller any,
)

func (*Router) HandleNamed

func (instance *Router) HandleNamed(name string, method string, pattern string, handler httpcontract.Handler)

func (*Router) HandleNamedController

func (instance *Router) HandleNamedController(
	name string,
	method string,
	pattern string,
	controller any,
)

func (*Router) HandleWithOptions

func (instance *Router) HandleWithOptions(pattern string, handler httpcontract.Handler, options httpcontract.RouteOptions)

func (*Router) Match

func (instance *Router) Match(method string, path string, host string, scheme string) (*httpcontract.MatchResult, bool)

func (*Router) RouteDefinition

func (instance *Router) RouteDefinition(routeName string) (httpcontract.RouteDefinition, bool)

func (*Router) RouteDefinitions

func (instance *Router) RouteDefinitions() []httpcontract.RouteDefinition

func (*Router) RouteRegistry

func (instance *Router) RouteRegistry() httpcontract.RouteRegistry

type UrlGenerationRouteDefinition

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

func NewUrlGenerationRouteDefinition

func NewUrlGenerationRouteDefinition(routeValue route) *UrlGenerationRouteDefinition

func (*UrlGenerationRouteDefinition) Defaults

func (instance *UrlGenerationRouteDefinition) Defaults() map[string]string

func (*UrlGenerationRouteDefinition) Pattern

func (instance *UrlGenerationRouteDefinition) Pattern() string

func (*UrlGenerationRouteDefinition) Requirements

func (instance *UrlGenerationRouteDefinition) Requirements() map[string]*regexp.Regexp

type UrlGenerator

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

func NewUrlGenerator

func NewUrlGenerator(routeRegistry httpcontract.RouteRegistry) *UrlGenerator

func (*UrlGenerator) GeneratePath

func (instance *UrlGenerator) GeneratePath(routeName string, parameters map[string]string) (string, error)

func (*UrlGenerator) GenerateUrl

func (instance *UrlGenerator) GenerateUrl(routeName string, params map[string]string, queryParams map[string]string) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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