Documentation
¶
Index ¶
- type Mapper
- func (m *Mapper) Collection(block func(*Mapper))
- func (m *Mapper) ConstraintsBlock(reqs map[string]string, block func(*Mapper))
- func (m *Mapper) Delete(path string, opts ...Option)
- func (m *Mapper) Get(path string, opts ...Option)
- func (m *Mapper) Match(path string, opts ...Option)
- func (m *Mapper) Member(block func(*Mapper))
- func (m *Mapper) Namespace(name string, block func(*Mapper))
- func (m *Mapper) Patch(path string, opts ...Option)
- func (m *Mapper) Post(path string, opts ...Option)
- func (m *Mapper) Put(path string, opts ...Option)
- func (m *Mapper) Resource(name string, block func(*Mapper), opts ...ResOption)
- func (m *Mapper) Resources(name string, block func(*Mapper), opts ...ResOption)
- func (m *Mapper) Root(target string, opts ...Option)
- func (m *Mapper) Scope(opts ScopeOpts, block func(*Mapper))
- type MissingRouteKeys
- type Option
- type Recognition
- type ResOption
- type Route
- type RouteNotFound
- type RouteSet
- func (rs *RouteSet) Draw(fn func(*Mapper)) error
- func (rs *RouteSet) Path(name string, params map[string]any) (string, error)
- func (rs *RouteSet) PathArgs(name string, args ...any) (string, error)
- func (rs *RouteSet) Recognize(method, path string) (*Recognition, bool)
- func (rs *RouteSet) Routes() []*Route
- func (rs *RouteSet) UrlFor(opts map[string]any) (string, error)
- type ScopeOpts
- type UnroutableParameters
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}
Mapper is the pure-Go analogue of ActionDispatch::Routing::Mapper: the receiver of the routing DSL evaluated inside RouteSet.Draw. It threads a lexical scope (path/module/name prefixes, constraints, defaults, and the enclosing resource) through nested blocks.
func (*Mapper) Collection ¶
Collection evaluates block adding routes at the :collection level of the enclosing resource (/resource/action).
func (*Mapper) ConstraintsBlock ¶
ConstraintsBlock evaluates block with added segment constraints.
func (*Mapper) Match ¶
Match adds a route responding to the methods given by Via (or any method when none are supplied).
func (*Mapper) Member ¶
Member evaluates block adding routes at the :member level of the enclosing resource (/resource/:id/action).
func (*Mapper) Namespace ¶
Namespace evaluates block under a path, module, and name prefix all equal to name (namespace :admin).
func (*Mapper) Resource ¶
Resource declares a singular RESTful resource (6 routes, no index, no :id).
func (*Mapper) Resources ¶
Resources declares a plural RESTful resource (7 routes). block, when non-nil, receives a mapper scoped to the resource for member/collection/nested routes.
type MissingRouteKeys ¶
MissingRouteKeys is returned by generation when required dynamic segments have no value.
func (*MissingRouteKeys) Error ¶
func (e *MissingRouteKeys) Error() string
type Option ¶
type Option func(*routeOpts)
Option customises a plain route (get/post/match).
func Constraints ¶
Constraints sets per-segment regexp requirements (raw, unanchored sources).
func Controller ¶
Controller sets the controller explicitly (used with Action).
type Recognition ¶
type Recognition struct {
Route *Route
Controller string
Action string
// Params holds the merged defaults and captured path segments (including
// "controller", "action", and, when present, "format").
Params map[string]any
}
Recognition is the outcome of recognizing a request: the matched route and the resolved controller, action, and path parameters.
type ResOption ¶
type ResOption func(*resConfig)
ResOption customises a resources/resource declaration.
func ResController ¶
ResController overrides the controller for the resource.
type Route ¶
type Route struct {
// Name is the path-helper base, or "" when the route adds no new helper.
Name string
// Verb is the upper-case HTTP method, or "" to match any method.
Verb string
// Spec is the raw path specification (e.g. "/posts/:id(.:format)").
Spec string
// Controller and Action are the dispatch target.
Controller string
Action string
// Defaults are parameters merged into every recognition of this route
// (they include "controller" and "action").
Defaults map[string]string
// contains filtered or unexported fields
}
Route is one compiled routing rule: an HTTP verb, a path pattern, and the controller/action it dispatches to, plus any default parameters and a reverse-routing name (the base of its path helper, e.g. "post" for post_path).
type RouteNotFound ¶
type RouteNotFound struct{ Name string }
RouteNotFound is returned by Path/PathArgs when no route carries the requested helper name.
func (*RouteNotFound) Error ¶
func (e *RouteNotFound) Error() string
type RouteSet ¶
type RouteSet struct {
// contains filtered or unexported fields
}
RouteSet is the pure-Go analogue of ActionDispatch::Routing::RouteSet: an ordered collection of routes with reverse-routing helpers. Recognition scans routes in definition order and returns the first match, exactly like Rails.
func (*RouteSet) Draw ¶
Draw evaluates the routing DSL in fn against a fresh Mapper and returns the first error encountered while compiling any path pattern.
func (*RouteSet) Path ¶
Path generates the path for the named route with the given parameters. Extra parameters that are not path segments become a sorted query string.
func (*RouteSet) PathArgs ¶
PathArgs generates the path for the named route from positional arguments, mapped to the route's required dynamic segments in order (post_path(1)). A trailing map[string]any argument supplies extra options (e.g. format or query parameters).
func (*RouteSet) Recognize ¶
func (rs *RouteSet) Recognize(method, path string) (*Recognition, bool)
Recognize maps an HTTP method and path to a controller, action, and parameters, returning ok=false when nothing matches.
type ScopeOpts ¶
type ScopeOpts struct {
Path string
Module string
As string
Constraints map[string]string
Defaults map[string]string
}
ScopeOpts are the prefixes and options a Scope block applies.
type UnroutableParameters ¶
UnroutableParameters is returned by UrlFor when no route matches the given controller/action.
func (*UnroutableParameters) Error ¶
func (e *UnroutableParameters) Error() string