contract

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 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
}

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)

	ServeHttp(serviceContainer containercontract.Container) nethttp.Handler
}

type MatchResult

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

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 added in v1.1.0

type RouteGroup interface {
	RouteHandler

	WithNamePrefix(namePrefix string)

	WithRequirements(requirements map[string]string)

	WithDefaults(defaults map[string]string)
}

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 SessionCookiePolicy

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

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