Documentation
¶
Index ¶
- Constants
- func CSSResponse(w http.ResponseWriter, r *http.Request, body string)
- func GetMiddlewareName(middleware Middleware) string
- func GetParam(r *http.Request, name string) (string, bool)
- func GetParams(r *http.Request) map[string]string
- func GetRouteMiddlewareNames(route RouteInterface) []string
- func HTMLResponse(w http.ResponseWriter, r *http.Request, body string)
- func JSONResponse(w http.ResponseWriter, r *http.Request, body string)
- func JSResponse(w http.ResponseWriter, r *http.Request, body string)
- func MustGetParam(r *http.Request, name string) string
- func RecoveryMiddleware(next http.Handler) http.Handler
- func TextResponse(w http.ResponseWriter, r *http.Request, body string)
- func XMLResponse(w http.ResponseWriter, r *http.Request, body string)
- type CSSHandler
- type DomainConfig
- func (d *DomainConfig) AddAfterMiddlewares(middleware []Middleware) DomainInterface
- func (d *DomainConfig) AddBeforeMiddlewares(middleware []Middleware) DomainInterface
- func (d *DomainConfig) AddGroup(group GroupInterface) DomainInterface
- func (d *DomainConfig) AddGroups(groups []GroupInterface) DomainInterface
- func (d *DomainConfig) AddRoute(route RouteInterface) DomainInterface
- func (d *DomainConfig) AddRoutes(routes []RouteInterface) DomainInterface
- func (d *DomainConfig) GetAfterMiddlewares() []Middleware
- func (d *DomainConfig) GetBeforeMiddlewares() []Middleware
- func (d *DomainConfig) GetGroups() []GroupInterface
- func (d *DomainConfig) GetPatterns() []string
- func (d *DomainConfig) GetRoutes() []RouteInterface
- func (d *DomainConfig) Match(host string) bool
- func (d *DomainConfig) SetPatterns(patterns ...string) DomainInterface
- type DomainInterface
- type ErrorHandler
- type GroupConfig
- func (g *GroupConfig) AddAfterMiddlewares(middleware []Middleware) GroupInterface
- func (g *GroupConfig) AddBeforeMiddlewares(middleware []Middleware) GroupInterface
- func (g *GroupConfig) AddGroup(group GroupInterface) GroupInterface
- func (g *GroupConfig) AddGroups(groups []GroupInterface) GroupInterface
- func (g *GroupConfig) AddRoute(route RouteInterface) GroupInterface
- func (g *GroupConfig) AddRoutes(routes []RouteInterface) GroupInterface
- func (g *GroupConfig) GetAfterMiddlewares() []Middleware
- func (g *GroupConfig) GetBeforeMiddlewares() []Middleware
- func (g *GroupConfig) GetGroups() []GroupInterface
- func (g *GroupConfig) GetPrefix() string
- func (g *GroupConfig) GetRoutes() []RouteInterface
- func (g *GroupConfig) SetPrefix(prefix string) GroupInterface
- func (g GroupConfig) WithAfterMiddleware(middleware ...Middleware) GroupConfig
- func (g GroupConfig) WithBeforeMiddleware(middleware ...Middleware) GroupConfig
- func (g GroupConfig) WithName(name string) GroupConfig
- type GroupInterface
- type HTMLHandler
- type Handler
- type JSHandler
- type JSONHandler
- type Middleware
- type MiddlewareInfo
- type RouteConfig
- func DELETE(path string, handler Handler) RouteConfig
- func GET(path string, handler Handler) RouteConfig
- func OPTIONS(path string, handler Handler) RouteConfig
- func PATCH(path string, handler Handler) RouteConfig
- func POST(path string, handler Handler) RouteConfig
- func PUT(path string, handler Handler) RouteConfig
- func (r *RouteConfig) AddAfterMiddlewares(middleware []Middleware) RouteInterface
- func (r *RouteConfig) AddBeforeMiddlewares(middleware []Middleware) RouteInterface
- func (r *RouteConfig) GetAfterMiddlewares() []Middleware
- func (r *RouteConfig) GetBeforeMiddlewares() []Middleware
- func (r *RouteConfig) GetCSSHandler() CSSHandler
- func (r *RouteConfig) GetErrorHandler() ErrorHandler
- func (r *RouteConfig) GetHTMLHandler() HTMLHandler
- func (r *RouteConfig) GetHandler() Handler
- func (r *RouteConfig) GetJSHandler() JSHandler
- func (r *RouteConfig) GetJSONHandler() JSONHandler
- func (r *RouteConfig) GetMetadata() map[string]interface{}
- func (r *RouteConfig) GetMethod() string
- func (r *RouteConfig) GetName() string
- func (r *RouteConfig) GetPath() string
- func (r *RouteConfig) GetStringHandler() StringHandler
- func (r *RouteConfig) GetTextHandler() TextHandler
- func (r *RouteConfig) GetXMLHandler() XMLHandler
- func (r *RouteConfig) SetCSSHandler(handler CSSHandler) RouteInterface
- func (r *RouteConfig) SetErrorHandler(handler ErrorHandler) RouteInterface
- func (r *RouteConfig) SetHTMLHandler(handler HTMLHandler) RouteInterface
- func (r *RouteConfig) SetHandler(handler Handler) RouteInterface
- func (r *RouteConfig) SetJSHandler(handler JSHandler) RouteInterface
- func (r *RouteConfig) SetJSONHandler(handler JSONHandler) RouteInterface
- func (r *RouteConfig) SetMetadata(metadata map[string]interface{}) RouteInterface
- func (r *RouteConfig) SetMethod(method string) RouteInterface
- func (r *RouteConfig) SetName(name string) RouteInterface
- func (r *RouteConfig) SetPath(path string) RouteInterface
- func (r *RouteConfig) SetStringHandler(handler StringHandler) RouteInterface
- func (r *RouteConfig) SetTextHandler(handler TextHandler) RouteInterface
- func (r *RouteConfig) SetXMLHandler(handler XMLHandler) RouteInterface
- func (r RouteConfig) WithAfterMiddleware(middleware ...Middleware) RouteConfig
- func (r RouteConfig) WithBeforeMiddleware(middleware ...Middleware) RouteConfig
- func (r RouteConfig) WithMetadata(key string, value interface{}) RouteConfig
- func (r RouteConfig) WithName(name string) RouteConfig
- type RouteInterface
- func Delete(path string, handler Handler) RouteInterface
- func Get(path string, handler Handler) RouteInterface
- func GetCSS(path string, handler CSSHandler) RouteInterface
- func GetHTML(path string, handler HTMLHandler) RouteInterface
- func GetJSON(path string, handler JSONHandler) RouteInterface
- func GetText(path string, handler TextHandler) RouteInterface
- func GetXML(path string, handler XMLHandler) RouteInterface
- func NewRoute() RouteInterface
- func Post(path string, handler Handler) RouteInterface
- func PostHTML(path string, handler HTMLHandler) RouteInterface
- func PostJSON(path string, handler JSONHandler) RouteInterface
- func Put(path string, handler Handler) RouteInterface
- type RouterConfig
- type RouterInterface
- type StringHandler
- type TextHandler
- type XMLHandler
Constants ¶
const ( // ParamsKey is the key used to store path parameters in the request context // Using a more specific key to avoid collisions with other packages ParamsKey contextKey = "rtr.path.params" )
Context key for storing path parameters in the request context
Variables ¶
This section is empty.
Functions ¶
func CSSResponse ¶ added in v0.4.0
func CSSResponse(w http.ResponseWriter, r *http.Request, body string)
CSSResponse responds with CSS content and sets the appropriate Content-Type header. It sets the Content-Type to "text/css".
func GetMiddlewareName ¶ added in v0.4.0
func GetMiddlewareName(middleware Middleware) string
GetMiddlewareName attempts to get a readable name for a middleware function
func GetParam ¶ added in v0.1.3
GetParam retrieves a path parameter from the request context by name. Returns the parameter value and true if found, or an empty string and false otherwise.
func GetParams ¶ added in v0.1.3
GetParams returns all path parameters as a map. Returns an empty map if no parameters exist.
func GetRouteMiddlewareNames ¶ added in v0.4.0
func GetRouteMiddlewareNames(route RouteInterface) []string
GetRouteMiddlewareNames gets middleware names for a route
func HTMLResponse ¶ added in v0.4.0
func HTMLResponse(w http.ResponseWriter, r *http.Request, body string)
HTMLResponse responds with HTML content and sets the appropriate Content-Type header. It sets the Content-Type to "text/html; charset=utf-8" if not already set.
func JSONResponse ¶ added in v0.4.0
func JSONResponse(w http.ResponseWriter, r *http.Request, body string)
JSONResponse responds with JSON content and sets the appropriate Content-Type header. It sets the Content-Type to "application/json".
func JSResponse ¶ added in v0.4.0
func JSResponse(w http.ResponseWriter, r *http.Request, body string)
JSResponse responds with JavaScript content and sets the appropriate Content-Type header. It sets the Content-Type to "application/javascript".
func MustGetParam ¶ added in v0.1.3
MustGetParam retrieves a path parameter from the request context by name. Panics if the parameter is not found. Use only when you're certain the parameter exists.
func RecoveryMiddleware ¶
RecoveryMiddleware creates a new middleware that recovers from panics. It logs the panic details and returns a 500 Internal Server Error response. This should typically be added as one of the first middlewares in the chain.
func TextResponse ¶ added in v0.4.0
func TextResponse(w http.ResponseWriter, r *http.Request, body string)
TextResponse responds with plain text content and sets the appropriate Content-Type header. It sets the Content-Type to "text/plain; charset=utf-8".
func XMLResponse ¶ added in v0.4.0
func XMLResponse(w http.ResponseWriter, r *http.Request, body string)
XMLResponse responds with XML content and sets the appropriate Content-Type header. It sets the Content-Type to "application/xml".
Types ¶
type CSSHandler ¶ added in v0.4.0
type CSSHandler StringHandler
CSSHandler is a convenience shorthand handler that returns CSS content. Automatically sets Content-Type: "text/css" header. Returns a CSS string that will be wrapped with CSSResponse().
type DomainConfig ¶ added in v0.3.0
type DomainConfig struct {
Name string `json:"name,omitempty"`
Patterns []string `json:"patterns"`
Routes []RouteConfig `json:"routes,omitempty"`
Groups []GroupConfig `json:"groups,omitempty"`
BeforeMiddleware []Middleware `json:"-"`
AfterMiddleware []Middleware `json:"-"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
DomainConfig represents a declarative domain configuration
func Domain ¶ added in v0.3.0
func Domain(patterns []string, items ...interface{}) DomainConfig
Domain creates a domain configuration
func (*DomainConfig) AddAfterMiddlewares ¶ added in v0.5.0
func (d *DomainConfig) AddAfterMiddlewares(middleware []Middleware) DomainInterface
AddAfterMiddlewares adds middleware functions to be executed after any route handler in this domain
func (*DomainConfig) AddBeforeMiddlewares ¶ added in v0.5.0
func (d *DomainConfig) AddBeforeMiddlewares(middleware []Middleware) DomainInterface
AddBeforeMiddlewares adds middleware functions to be executed before any route handler in this domain
func (*DomainConfig) AddGroup ¶ added in v0.5.0
func (d *DomainConfig) AddGroup(group GroupInterface) DomainInterface
AddGroup adds a group to this domain and returns the domain for method chaining
func (*DomainConfig) AddGroups ¶ added in v0.5.0
func (d *DomainConfig) AddGroups(groups []GroupInterface) DomainInterface
AddGroups adds multiple groups to this domain and returns the domain for method chaining
func (*DomainConfig) AddRoute ¶ added in v0.5.0
func (d *DomainConfig) AddRoute(route RouteInterface) DomainInterface
AddRoute adds a route to this domain and returns the domain for method chaining
func (*DomainConfig) AddRoutes ¶ added in v0.5.0
func (d *DomainConfig) AddRoutes(routes []RouteInterface) DomainInterface
AddRoutes adds multiple routes to this domain and returns the domain for method chaining
func (*DomainConfig) GetAfterMiddlewares ¶ added in v0.5.0
func (d *DomainConfig) GetAfterMiddlewares() []Middleware
GetAfterMiddlewares returns all middleware functions that will be executed after any route handler in this domain
func (*DomainConfig) GetBeforeMiddlewares ¶ added in v0.5.0
func (d *DomainConfig) GetBeforeMiddlewares() []Middleware
GetBeforeMiddlewares returns all middleware functions that will be executed before any route handler in this domain
func (*DomainConfig) GetGroups ¶ added in v0.5.0
func (d *DomainConfig) GetGroups() []GroupInterface
GetGroups returns all groups that belong to this domain
func (*DomainConfig) GetPatterns ¶ added in v0.5.0
func (d *DomainConfig) GetPatterns() []string
GetPatterns returns the domain patterns that this domain matches against
func (*DomainConfig) GetRoutes ¶ added in v0.5.0
func (d *DomainConfig) GetRoutes() []RouteInterface
GetRoutes returns all routes that belong to this domain
func (*DomainConfig) Match ¶ added in v0.5.0
func (d *DomainConfig) Match(host string) bool
Match checks if the given host matches any of this domain's patterns
func (*DomainConfig) SetPatterns ¶ added in v0.5.0
func (d *DomainConfig) SetPatterns(patterns ...string) DomainInterface
SetPatterns sets the domain patterns for this domain and returns the domain for method chaining
type DomainInterface ¶
type DomainInterface interface {
// GetPatterns returns the domain patterns that this domain matches against
GetPatterns() []string
// SetPatterns sets the domain patterns for this domain and returns the domain for method chaining
SetPatterns(patterns ...string) DomainInterface
// AddRoute adds a route to this domain and returns the domain for method chaining
AddRoute(route RouteInterface) DomainInterface
// AddRoutes adds multiple routes to this domain and returns the domain for method chaining
AddRoutes(routes []RouteInterface) DomainInterface
// GetRoutes returns all routes that belong to this domain
GetRoutes() []RouteInterface
// AddGroup adds a group to this domain and returns the domain for method chaining
AddGroup(group GroupInterface) DomainInterface
// AddGroups adds multiple groups to this domain and returns the domain for method chaining
AddGroups(groups []GroupInterface) DomainInterface
// GetGroups returns all groups that belong to this domain
GetGroups() []GroupInterface
// AddBeforeMiddlewares adds middleware functions to be executed before any route handler in this domain
// Returns the domain for method chaining
AddBeforeMiddlewares(middleware []Middleware) DomainInterface
// GetBeforeMiddlewares returns all middleware functions that will be executed before any route handler in this domain
GetBeforeMiddlewares() []Middleware
// AddAfterMiddlewares adds middleware functions to be executed after any route handler in this domain
// Returns the domain for method chaining
AddAfterMiddlewares(middleware []Middleware) DomainInterface
// GetAfterMiddlewares returns all middleware functions that will be executed after any route handler in this domain
GetAfterMiddlewares() []Middleware
// Match checks if the given host matches any of this domain's patterns
Match(host string) bool
}
DomainInterface defines the interface for a domain that can have routes and groups. A domain represents a collection of routes and groups that are only accessible when the request's Host header matches the domain's patterns.
func NewDomain ¶
func NewDomain(patterns ...string) DomainInterface
NewDomain creates a new domain with the given patterns
type ErrorHandler ¶ added in v0.4.0
type ErrorHandler func(http.ResponseWriter, *http.Request) error
ErrorHandler is a convenience shorthand handler for error responses. Returns an error that will be handled appropriately. If the returned error is nil, it means no error occurred and the response is successful. Content-Type and status codes are left to specific extensions like 404ErrorHandler.
type GroupConfig ¶ added in v0.3.0
type GroupConfig struct {
Name string `json:"name,omitempty"`
Prefix string `json:"prefix"`
Routes []RouteConfig `json:"routes,omitempty"`
Groups []GroupConfig `json:"groups,omitempty"`
BeforeMiddleware []Middleware `json:"-"`
AfterMiddleware []Middleware `json:"-"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
GroupConfig represents a declarative group configuration
func Group ¶ added in v0.3.0
func Group(prefix string, items ...interface{}) GroupConfig
Group creates a group configuration
func (*GroupConfig) AddAfterMiddlewares ¶ added in v0.5.0
func (g *GroupConfig) AddAfterMiddlewares(middleware []Middleware) GroupInterface
AddAfterMiddlewares adds middleware functions to be executed after any route handler in this group.
func (*GroupConfig) AddBeforeMiddlewares ¶ added in v0.5.0
func (g *GroupConfig) AddBeforeMiddlewares(middleware []Middleware) GroupInterface
AddBeforeMiddlewares adds middleware functions to be executed before any route handler in this group.
func (*GroupConfig) AddGroup ¶ added in v0.5.0
func (g *GroupConfig) AddGroup(group GroupInterface) GroupInterface
AddGroup adds a single nested group to this group and returns the group for method chaining.
func (*GroupConfig) AddGroups ¶ added in v0.5.0
func (g *GroupConfig) AddGroups(groups []GroupInterface) GroupInterface
AddGroups adds multiple nested groups to this group and returns the group for method chaining.
func (*GroupConfig) AddRoute ¶ added in v0.5.0
func (g *GroupConfig) AddRoute(route RouteInterface) GroupInterface
AddRoute adds a single route to this group and returns the group for method chaining.
func (*GroupConfig) AddRoutes ¶ added in v0.5.0
func (g *GroupConfig) AddRoutes(routes []RouteInterface) GroupInterface
AddRoutes adds multiple routes to this group and returns the group for method chaining.
func (*GroupConfig) GetAfterMiddlewares ¶ added in v0.5.0
func (g *GroupConfig) GetAfterMiddlewares() []Middleware
GetAfterMiddlewares returns all middleware functions that will be executed after any route handler in this group.
func (*GroupConfig) GetBeforeMiddlewares ¶ added in v0.5.0
func (g *GroupConfig) GetBeforeMiddlewares() []Middleware
GetBeforeMiddlewares returns all middleware functions that will be executed before any route handler in this group.
func (*GroupConfig) GetGroups ¶ added in v0.5.0
func (g *GroupConfig) GetGroups() []GroupInterface
GetGroups returns all nested groups that belong to this group.
func (*GroupConfig) GetPrefix ¶ added in v0.5.0
func (g *GroupConfig) GetPrefix() string
GetPrefix returns the URL path prefix associated with this group.
func (*GroupConfig) GetRoutes ¶ added in v0.5.0
func (g *GroupConfig) GetRoutes() []RouteInterface
GetRoutes returns all routes that belong to this group.
func (*GroupConfig) SetPrefix ¶ added in v0.5.0
func (g *GroupConfig) SetPrefix(prefix string) GroupInterface
SetPrefix sets the URL path prefix for this group and returns the group for method chaining.
func (GroupConfig) WithAfterMiddleware ¶ added in v0.3.0
func (g GroupConfig) WithAfterMiddleware(middleware ...Middleware) GroupConfig
WithAfterMiddleware adds after middleware to a group configuration
func (GroupConfig) WithBeforeMiddleware ¶ added in v0.3.0
func (g GroupConfig) WithBeforeMiddleware(middleware ...Middleware) GroupConfig
WithBeforeMiddleware adds before middleware to a group configuration
func (GroupConfig) WithName ¶ added in v0.3.0
func (g GroupConfig) WithName(name string) GroupConfig
WithName adds a name to a group configuration
type GroupInterface ¶
type GroupInterface interface {
// GetPrefix returns the URL path prefix associated with this group.
GetPrefix() string
// SetPrefix sets the URL path prefix for this group and returns the group for method chaining.
SetPrefix(prefix string) GroupInterface
// AddRoute adds a single route to this group and returns the group for method chaining.
AddRoute(route RouteInterface) GroupInterface
// AddRoutes adds multiple routes to this group and returns the group for method chaining.
AddRoutes(routes []RouteInterface) GroupInterface
// GetRoutes returns all routes that belong to this group.
GetRoutes() []RouteInterface
// AddGroup adds a single nested group to this group and returns the group for method chaining.
AddGroup(group GroupInterface) GroupInterface
// AddGroups adds multiple nested groups to this group and returns the group for method chaining.
AddGroups(groups []GroupInterface) GroupInterface
// GetGroups returns all nested groups that belong to this group.
GetGroups() []GroupInterface
// AddBeforeMiddlewares adds middleware functions to be executed before any route handler in this group.
// Returns the group for method chaining.
AddBeforeMiddlewares(middleware []Middleware) GroupInterface
// GetBeforeMiddlewares returns all middleware functions that will be executed before any route handler in this group.
GetBeforeMiddlewares() []Middleware
// AddAfterMiddlewares adds middleware functions to be executed after any route handler in this group.
// Returns the group for method chaining.
AddAfterMiddlewares(middleware []Middleware) GroupInterface
// GetAfterMiddlewares returns all middleware functions that will be executed after any route handler in this group.
GetAfterMiddlewares() []Middleware
}
GroupInterface defines the interface for a group of routes. A group represents a collection of routes that share common properties such as a URL prefix and middleware. Groups can also be nested to create hierarchical route structures.
func NewGroup ¶
func NewGroup() GroupInterface
NewGroup creates and returns a new GroupInterface implementation. This is used to create a new route group that can be added to a router.
type HTMLHandler ¶ added in v0.4.0
type HTMLHandler StringHandler
HTMLHandler is a convenience shorthand handler that returns HTML content. Automatically sets Content-Type: "text/html; charset=utf-8" header. Returns an HTML string that will be wrapped with HTMLResponse().
type Handler ¶
type Handler func(http.ResponseWriter, *http.Request)
Handler defines the function signature for HTTP request handlers.
func ErrorHandlerToHandler ¶ added in v0.4.0
func ErrorHandlerToHandler(handler ErrorHandler) Handler
ErrorHandlerToHandler converts an ErrorHandler to a standard Handler. If the error handler returns an error, it writes the error message to the response. If the error handler returns nil, it does nothing.
Parameters:
- handler: The error handler function to convert.
Returns:
- A standard Handler function that writes the error message to the response if an error is returned.
func ToHandler ¶ added in v0.4.0
func ToHandler(handler StringHandler) Handler
ToHandler converts any string-returning handler to a standard Handler. It simply writes the returned string to the response without setting any headers. The string handler is responsible for setting any headers it needs.
Parameters:
- handler: The string handler function to convert.
Returns:
- A standard Handler function that writes the returned string to the response.
type JSHandler ¶ added in v0.4.0
type JSHandler StringHandler
JSHandler is a convenience shorthand handler that returns JavaScript content. Automatically sets Content-Type: "application/javascript" header. Returns a JavaScript string that will be wrapped with JSResponse().
type JSONHandler ¶ added in v0.4.0
type JSONHandler StringHandler
JSONHandler is a convenience shorthand handler that returns JSON content. Automatically sets Content-Type: "application/json" header. Returns a JSON string that will be wrapped with JSONResponse().
type Middleware ¶
Middleware represents a middleware function. It is a function type that takes an http.Handler and returns an http.Handler. Middleware functions can be used to process requests before or after they reach the main handler.
func DefaultMiddlewares ¶
func DefaultMiddlewares() []Middleware
DefaultMiddlewares returns a slice of default middlewares that should be used with the router. Currently, it only includes the RecoveryMiddleware.
type MiddlewareInfo ¶ added in v0.2.0
type MiddlewareInfo struct {
Name string
Func Middleware
}
MiddlewareInfo represents middleware information for display purposes
type RouteConfig ¶ added in v0.3.0
type RouteConfig struct {
Name string `json:"name,omitempty"`
Method string `json:"method,omitempty"`
Path string `json:"path"`
Handler Handler `json:"-"`
ErrorHandler ErrorHandler `json:"-"`
HTMLHandler HTMLHandler `json:"-"`
JSONHandler JSONHandler `json:"-"`
CSSHandler CSSHandler `json:"-"`
XMLHandler XMLHandler `json:"-"`
TextHandler TextHandler `json:"-"`
BeforeMiddleware []Middleware `json:"-"`
AfterMiddleware []Middleware `json:"-"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
RouteConfig represents a declarative route configuration
func DELETE ¶ added in v0.3.0
func DELETE(path string, handler Handler) RouteConfig
DELETE creates a DELETE route configuration
func GET ¶ added in v0.3.0
func GET(path string, handler Handler) RouteConfig
GET creates a GET route configuration
func OPTIONS ¶ added in v0.3.0
func OPTIONS(path string, handler Handler) RouteConfig
OPTIONS creates an OPTIONS route configuration
func PATCH ¶ added in v0.3.0
func PATCH(path string, handler Handler) RouteConfig
PATCH creates a PATCH route configuration
func POST ¶ added in v0.3.0
func POST(path string, handler Handler) RouteConfig
POST creates a POST route configuration
func PUT ¶ added in v0.3.0
func PUT(path string, handler Handler) RouteConfig
PUT creates a PUT route configuration
func (*RouteConfig) AddAfterMiddlewares ¶ added in v0.5.0
func (r *RouteConfig) AddAfterMiddlewares(middleware []Middleware) RouteInterface
AddAfterMiddlewares adds middleware functions to be executed after the route handler.
func (*RouteConfig) AddBeforeMiddlewares ¶ added in v0.5.0
func (r *RouteConfig) AddBeforeMiddlewares(middleware []Middleware) RouteInterface
AddBeforeMiddlewares adds middleware functions to be executed before the route handler.
func (*RouteConfig) GetAfterMiddlewares ¶ added in v0.5.0
func (r *RouteConfig) GetAfterMiddlewares() []Middleware
GetAfterMiddlewares returns all middleware functions that will be executed after the route handler.
func (*RouteConfig) GetBeforeMiddlewares ¶ added in v0.5.0
func (r *RouteConfig) GetBeforeMiddlewares() []Middleware
GetBeforeMiddlewares returns all middleware functions that will be executed before the route handler.
func (*RouteConfig) GetCSSHandler ¶ added in v0.5.0
func (r *RouteConfig) GetCSSHandler() CSSHandler
GetCSSHandler returns the CSS handler function associated with this route.
func (*RouteConfig) GetErrorHandler ¶ added in v0.5.0
func (r *RouteConfig) GetErrorHandler() ErrorHandler
GetErrorHandler returns the error handler function associated with this route.
func (*RouteConfig) GetHTMLHandler ¶ added in v0.5.0
func (r *RouteConfig) GetHTMLHandler() HTMLHandler
GetHTMLHandler returns the HTML handler function associated with this route.
func (*RouteConfig) GetHandler ¶ added in v0.5.0
func (r *RouteConfig) GetHandler() Handler
GetHandler returns the handler function associated with this route.
func (*RouteConfig) GetJSHandler ¶ added in v0.5.0
func (r *RouteConfig) GetJSHandler() JSHandler
GetJSHandler returns the JavaScript handler function associated with this route.
func (*RouteConfig) GetJSONHandler ¶ added in v0.5.0
func (r *RouteConfig) GetJSONHandler() JSONHandler
GetJSONHandler returns the JSON handler function associated with this route.
func (*RouteConfig) GetMetadata ¶ added in v0.5.0
func (r *RouteConfig) GetMetadata() map[string]interface{}
GetMetadata returns the metadata associated with this route.
func (*RouteConfig) GetMethod ¶ added in v0.5.0
func (r *RouteConfig) GetMethod() string
GetMethod returns the HTTP method associated with this route.
func (*RouteConfig) GetName ¶ added in v0.5.0
func (r *RouteConfig) GetName() string
GetName returns the name associated with this route.
func (*RouteConfig) GetPath ¶ added in v0.5.0
func (r *RouteConfig) GetPath() string
GetPath returns the URL path pattern associated with this route.
func (*RouteConfig) GetStringHandler ¶ added in v0.5.0
func (r *RouteConfig) GetStringHandler() StringHandler
GetStringHandler returns the string handler function associated with this route.
func (*RouteConfig) GetTextHandler ¶ added in v0.5.0
func (r *RouteConfig) GetTextHandler() TextHandler
GetTextHandler returns the text handler function associated with this route.
func (*RouteConfig) GetXMLHandler ¶ added in v0.5.0
func (r *RouteConfig) GetXMLHandler() XMLHandler
GetXMLHandler returns the XML handler function associated with this route.
func (*RouteConfig) SetCSSHandler ¶ added in v0.5.0
func (r *RouteConfig) SetCSSHandler(handler CSSHandler) RouteInterface
SetCSSHandler sets the CSS handler function for this route and returns the route for method chaining.
func (*RouteConfig) SetErrorHandler ¶ added in v0.5.0
func (r *RouteConfig) SetErrorHandler(handler ErrorHandler) RouteInterface
SetErrorHandler sets the error handler function for this route and returns the route for method chaining.
func (*RouteConfig) SetHTMLHandler ¶ added in v0.5.0
func (r *RouteConfig) SetHTMLHandler(handler HTMLHandler) RouteInterface
SetHTMLHandler sets the HTML handler function for this route and returns the route for method chaining.
func (*RouteConfig) SetHandler ¶ added in v0.5.0
func (r *RouteConfig) SetHandler(handler Handler) RouteInterface
SetHandler sets the handler function for this route and returns the route for method chaining.
func (*RouteConfig) SetJSHandler ¶ added in v0.5.0
func (r *RouteConfig) SetJSHandler(handler JSHandler) RouteInterface
SetJSHandler sets the JavaScript handler function for this route and returns the route for method chaining.
func (*RouteConfig) SetJSONHandler ¶ added in v0.5.0
func (r *RouteConfig) SetJSONHandler(handler JSONHandler) RouteInterface
SetJSONHandler sets the JSON handler function for this route and returns the route for method chaining.
func (*RouteConfig) SetMetadata ¶ added in v0.5.0
func (r *RouteConfig) SetMetadata(metadata map[string]interface{}) RouteInterface
SetMetadata sets the metadata for this route and returns the route for method chaining.
func (*RouteConfig) SetMethod ¶ added in v0.5.0
func (r *RouteConfig) SetMethod(method string) RouteInterface
SetMethod sets the HTTP method for this route and returns the route for method chaining.
func (*RouteConfig) SetName ¶ added in v0.5.0
func (r *RouteConfig) SetName(name string) RouteInterface
SetName sets the name for this route and returns the route for method chaining.
func (*RouteConfig) SetPath ¶ added in v0.5.0
func (r *RouteConfig) SetPath(path string) RouteInterface
SetPath sets the URL path pattern for this route and returns the route for method chaining.
func (*RouteConfig) SetStringHandler ¶ added in v0.5.0
func (r *RouteConfig) SetStringHandler(handler StringHandler) RouteInterface
SetStringHandler sets the string handler function for this route and returns the route for method chaining.
func (*RouteConfig) SetTextHandler ¶ added in v0.5.0
func (r *RouteConfig) SetTextHandler(handler TextHandler) RouteInterface
SetTextHandler sets the text handler function for this route and returns the route for method chaining.
func (*RouteConfig) SetXMLHandler ¶ added in v0.5.0
func (r *RouteConfig) SetXMLHandler(handler XMLHandler) RouteInterface
SetXMLHandler sets the XML handler function for this route and returns the route for method chaining.
func (RouteConfig) WithAfterMiddleware ¶ added in v0.3.0
func (r RouteConfig) WithAfterMiddleware(middleware ...Middleware) RouteConfig
WithAfterMiddleware adds after middleware to a route configuration
func (RouteConfig) WithBeforeMiddleware ¶ added in v0.3.0
func (r RouteConfig) WithBeforeMiddleware(middleware ...Middleware) RouteConfig
WithBeforeMiddleware adds before middleware to a route configuration
func (RouteConfig) WithMetadata ¶ added in v0.3.0
func (r RouteConfig) WithMetadata(key string, value interface{}) RouteConfig
WithMetadata adds metadata to a route configuration
func (RouteConfig) WithName ¶ added in v0.3.0
func (r RouteConfig) WithName(name string) RouteConfig
WithName adds a name to a route configuration
type RouteInterface ¶
type RouteInterface interface {
// GetMethod returns the HTTP method associated with this route.
GetMethod() string
// SetMethod sets the HTTP method for this route and returns the route for method chaining.
SetMethod(method string) RouteInterface
// GetPath returns the URL path pattern associated with this route.
GetPath() string
// SetPath sets the URL path pattern for this route and returns the route for method chaining.
SetPath(path string) RouteInterface
// GetHandler returns the handler function associated with this route.
GetHandler() Handler
// SetHandler sets the handler function for this route and returns the route for method chaining.
SetHandler(handler Handler) RouteInterface
// GetStringHandler returns the string handler function associated with this route.
GetStringHandler() StringHandler
// SetStringHandler sets the string handler function for this route and returns the route for method chaining.
SetStringHandler(handler StringHandler) RouteInterface
// GetHTMLHandler returns the HTML handler function associated with this route.
GetHTMLHandler() HTMLHandler
// SetHTMLHandler sets the HTML handler function for this route and returns the route for method chaining.
SetHTMLHandler(handler HTMLHandler) RouteInterface
// GetJSONHandler returns the JSON handler function associated with this route.
GetJSONHandler() JSONHandler
// SetJSONHandler sets the JSON handler function for this route and returns the route for method chaining.
SetJSONHandler(handler JSONHandler) RouteInterface
// GetCSSHandler returns the CSS handler function associated with this route.
GetCSSHandler() CSSHandler
// SetCSSHandler sets the CSS handler function for this route and returns the route for method chaining.
SetCSSHandler(handler CSSHandler) RouteInterface
// GetXMLHandler returns the XML handler function associated with this route.
GetXMLHandler() XMLHandler
// SetXMLHandler sets the XML handler function for this route and returns the route for method chaining.
SetXMLHandler(handler XMLHandler) RouteInterface
// GetTextHandler returns the text handler function associated with this route.
GetTextHandler() TextHandler
// SetTextHandler sets the text handler function for this route and returns the route for method chaining.
SetTextHandler(handler TextHandler) RouteInterface
// GetJSHandler returns the JavaScript handler function associated with this route.
GetJSHandler() JSHandler
// SetJSHandler sets the JavaScript handler function for this route and returns the route for method chaining.
SetJSHandler(handler JSHandler) RouteInterface
// GetErrorHandler returns the error handler function associated with this route.
GetErrorHandler() ErrorHandler
// SetErrorHandler sets the error handler function for this route and returns the route for method chaining.
SetErrorHandler(handler ErrorHandler) RouteInterface
// GetName returns the name identifier associated with this route.
GetName() string
// SetName sets the name identifier for this route and returns the route for method chaining.
SetName(name string) RouteInterface
// AddBeforeMiddlewares adds middleware functions to be executed before the route handler.
// Returns the route for method chaining.
AddBeforeMiddlewares(middleware []Middleware) RouteInterface
// GetBeforeMiddlewares returns all middleware functions that will be executed before the route handler.
GetBeforeMiddlewares() []Middleware
// AddAfterMiddlewares adds middleware functions to be executed after the route handler.
// Returns the route for method chaining.
AddAfterMiddlewares(middleware []Middleware) RouteInterface
// GetAfterMiddlewares returns all middleware functions that will be executed after the route handler.
GetAfterMiddlewares() []Middleware
}
RouteInterface defines the interface for a single route definition. A route represents a mapping between an HTTP method, a URL path pattern, and a handler function. Routes can also have associated middleware that will be executed before or after the handler.
func Delete ¶
func Delete(path string, handler Handler) RouteInterface
Delete creates a new DELETE route with the given path and handler It is a shortcut method that combines setting the method to DELETE, path, and handler.
func Get ¶
func Get(path string, handler Handler) RouteInterface
Get creates a new GET route with the given path and handler It is a shortcut method that combines setting the method to GET, path, and handler.
func GetCSS ¶ added in v0.4.0
func GetCSS(path string, handler CSSHandler) RouteInterface
GetCSS creates a new GET route with the given path and CSS handler It is a shortcut method that combines setting the method to GET, path, and CSS handler.
func GetHTML ¶ added in v0.4.0
func GetHTML(path string, handler HTMLHandler) RouteInterface
GetHTML creates a new GET route with the given path and HTML handler It is a shortcut method that combines setting the method to GET, path, and HTML handler.
func GetJSON ¶ added in v0.4.0
func GetJSON(path string, handler JSONHandler) RouteInterface
GetJSON creates a new GET route with the given path and JSON handler It is a shortcut method that combines setting the method to GET, path, and JSON handler.
func GetText ¶ added in v0.4.0
func GetText(path string, handler TextHandler) RouteInterface
GetText creates a new GET route with the given path and text handler It is a shortcut method that combines setting the method to GET, path, and text handler.
func GetXML ¶ added in v0.4.0
func GetXML(path string, handler XMLHandler) RouteInterface
GetXML creates a new GET route with the given path and XML handler It is a shortcut method that combines setting the method to GET, path, and XML handler.
func NewRoute ¶
func NewRoute() RouteInterface
This is used to create a new route that can be added to a router or group.
func Post ¶
func Post(path string, handler Handler) RouteInterface
Post creates a new POST route with the given path and handler It is a shortcut method that combines setting the method to POST, path, and handler.
func PostHTML ¶ added in v0.4.0
func PostHTML(path string, handler HTMLHandler) RouteInterface
PostHTML creates a new POST route with the given path and HTML handler It is a shortcut method that combines setting the method to POST, path, and HTML handler.
func PostJSON ¶ added in v0.4.0
func PostJSON(path string, handler JSONHandler) RouteInterface
PostJSON creates a new POST route with the given path and JSON handler It is a shortcut method that combines setting the method to POST, path, and JSON handler.
func Put ¶
func Put(path string, handler Handler) RouteInterface
Put creates a new PUT route with the given path and handler It is a shortcut method that combines setting the method to PUT, path, and handler.
type RouterConfig ¶ added in v0.3.0
type RouterConfig struct {
Name string `json:"name,omitempty"`
Prefix string `json:"prefix,omitempty"`
Routes []RouteConfig `json:"routes,omitempty"`
Groups []GroupConfig `json:"groups,omitempty"`
Domains []DomainConfig `json:"domains,omitempty"`
BeforeMiddleware []Middleware `json:"-"`
AfterMiddleware []Middleware `json:"-"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
RouterConfig represents a complete declarative router configuration
type RouterInterface ¶
type RouterInterface interface {
// GetPrefix returns the URL path prefix associated with this router.
GetPrefix() string
// SetPrefix sets the URL path prefix for this router and returns the router for method chaining.
// The prefix will be prepended to all routes in this router.
SetPrefix(prefix string) RouterInterface
// AddGroup adds a single group to this router and returns the router for method chaining.
// The group's prefix will be combined with the router's prefix for all routes in the group.
AddGroup(group GroupInterface) RouterInterface
// AddGroups adds multiple groups to this router and returns the router for method chaining.
// Each group's prefix will be combined with the router's prefix for all routes in the group.
AddGroups(groups []GroupInterface) RouterInterface
// GetGroups returns all groups that belong to this router.
// Returns a slice of GroupInterface implementations.
GetGroups() []GroupInterface
// AddRoute adds a single route to this router and returns the router for method chaining.
// The route's path will be prefixed with the router's prefix.
AddRoute(route RouteInterface) RouterInterface
// AddRoutes adds multiple routes to this router and returns the router for method chaining.
// Each route's path will be prefixed with the router's prefix.
AddRoutes(routes []RouteInterface) RouterInterface
// GetRoutes returns all routes that belong to this router.
// Returns a slice of RouteInterface implementations.
GetRoutes() []RouteInterface
// AddBeforeMiddlewares adds middleware functions to be executed before any route handler.
// The middleware functions will be executed in the order they are added.
// Returns the router for method chaining.
AddBeforeMiddlewares(middleware []Middleware) RouterInterface
// GetBeforeMiddlewares returns all middleware functions that will be executed before any route handler.
// Returns a slice of Middleware functions.
GetBeforeMiddlewares() []Middleware
// AddAfterMiddlewares adds middleware functions to be executed after any route handler.
// The middleware functions will be executed in reverse order of how they were added.
// Returns the router for method chaining.
AddAfterMiddlewares(middleware []Middleware) RouterInterface
// GetAfterMiddlewares returns all middleware functions that will be executed after any route handler.
// Returns a slice of Middleware functions.
GetAfterMiddlewares() []Middleware
// AddDomain adds a domain to this router and returns the router for method chaining
AddDomain(domain DomainInterface) RouterInterface
// AddDomains adds multiple domains to this router and returns the router for method chaining
AddDomains(domains []DomainInterface) RouterInterface
// GetDomains returns all domains that belong to this router
GetDomains() []DomainInterface
// List displays the router's configuration in formatted tables for debugging and documentation
// Shows global middleware, domains, direct routes, and route groups
List()
// ServeHTTP implements the http.Handler interface.
// It matches the incoming request to the appropriate route and executes the handler.
ServeHTTP(w http.ResponseWriter, r *http.Request)
}
RouterInterface defines the interface for a router that can handle HTTP requests. A router is responsible for matching incoming HTTP requests to the appropriate route handler and executing any associated middleware.
func NewRouter ¶
func NewRouter() RouterInterface
NewRouter creates and returns a new RouterInterface implementation. This is the main entry point for creating a new router. By default, it includes recovery middleware to handle panics.
func NewRouterFromConfig ¶ added in v0.3.0
func NewRouterFromConfig(config RouterConfig) RouterInterface
NewRouterFromConfig creates a router from a declarative configuration
type StringHandler ¶ added in v0.4.0
type StringHandler func(http.ResponseWriter, *http.Request) string
StringHandler is a convenience shorthand handler for simple string responses. It returns a string that will be written directly to the response without setting any headers. The handler is responsible for setting any headers it needs.
type TextHandler ¶ added in v0.4.0
type TextHandler StringHandler
TextHandler is a convenience shorthand handler that returns plain text content. Automatically sets Content-Type: "text/plain; charset=utf-8" header. Returns a plain text string that will be wrapped with TextResponse().
type XMLHandler ¶ added in v0.4.0
type XMLHandler StringHandler
XMLHandler is a convenience shorthand handler that returns XML content. Automatically sets Content-Type: "application/xml" header. Returns an XML string that will be wrapped with XMLResponse().
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
basic
command
|
|
|
declarative
command
|
|
|
domain
command
|
|
|
handlers
command
|
|
|
path-parameters
command
|