Documentation
¶
Index ¶
- Variables
- type Exporter
- type Group
- func (g *Group) DELETE(path string, handlers ...gin.HandlerFunc) *Route
- func (g *Group) GET(path string, handlers ...gin.HandlerFunc) *Route
- func (g *Group) Group(prefix string, mw ...gin.HandlerFunc) *Group
- func (g *Group) HEAD(path string, handlers ...gin.HandlerFunc) *Route
- func (g *Group) Internal(prefix string) *Group
- func (g *Group) OPTIONS(path string, handlers ...gin.HandlerFunc) *Route
- func (g *Group) PATCH(path string, handlers ...gin.HandlerFunc) *Route
- func (g *Group) POST(path string, handlers ...gin.HandlerFunc) *Route
- func (g *Group) PUT(path string, handlers ...gin.HandlerFunc) *Route
- func (g *Group) Param(name string, p *Pattern) *Group
- func (g *Group) Policy(names ...string) *Group
- type Pattern
- type Registry
- type Route
- func (r *Route) IsInternal() bool
- func (r *Route) IsStatic() bool
- func (r *Route) Method() string
- func (r *Route) Param(name string, p *Pattern) *Route
- func (r *Route) Params() map[string]*Pattern
- func (r *Route) Path() string
- func (r *Route) PathRegex() string
- func (r *Route) Policies() []string
- func (r *Route) Policy(names ...string) *Route
- type Set
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknownPolicy = fmt.Errorf("unknown policy") ErrUnknownParam = fmt.Errorf("unknown path param") ErrInvalidParamPattern = fmt.Errorf("invalid param pattern") ErrDuplicateRoute = fmt.Errorf("duplicate route") ErrAmbiguousRoute = fmt.Errorf("ambiguous route") ErrDuplicatePolicy = fmt.Errorf("duplicate policy") )
var ( // UUID matches a UUID in its 8-4-4-4-12 hex form, in either letter case. UUID = &Pattern{expr: `[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`} // Numeric matches one or more ASCII digits. Numeric = &Pattern{expr: `[0-9]+`} )
Predefined patterns for Param.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group defines routes under a shared path prefix. Its middleware, policies, params and internal status apply to every route and nested group in it, whether set before or after they are defined. Paths passed to GET, POST and the other method helpers are relative to the prefix, "/" maps to the prefix itself.
Groups and routes must not be changed after DefineRoutes returns. The router keeps what was registered, while later exports would pick up the change and no longer match what the service serves.
func (*Group) DELETE ¶
func (g *Group) DELETE(path string, handlers ...gin.HandlerFunc) *Route
DELETE defines a DELETE route at path, relative to the group prefix, served by handlers.
func (*Group) GET ¶
func (g *Group) GET(path string, handlers ...gin.HandlerFunc) *Route
GET defines a GET route at path, relative to the group prefix, served by handlers.
func (*Group) Group ¶
func (g *Group) Group(prefix string, mw ...gin.HandlerFunc) *Group
Group creates a nested group under prefix. mw is plain gin middleware that runs only in the service, before the param check and policies of each route.
func (*Group) HEAD ¶
func (g *Group) HEAD(path string, handlers ...gin.HandlerFunc) *Route
HEAD defines a HEAD route at path, relative to the group prefix, served by handlers.
func (*Group) Internal ¶
Internal creates a nested group whose routes are served but left out of route exports.
func (*Group) OPTIONS ¶
func (g *Group) OPTIONS(path string, handlers ...gin.HandlerFunc) *Route
OPTIONS defines an OPTIONS route at path, relative to the group prefix, served by handlers.
func (*Group) PATCH ¶
func (g *Group) PATCH(path string, handlers ...gin.HandlerFunc) *Route
PATCH defines a PATCH route at path, relative to the group prefix, served by handlers.
func (*Group) POST ¶
func (g *Group) POST(path string, handlers ...gin.HandlerFunc) *Route
POST defines a POST route at path, relative to the group prefix, served by handlers.
func (*Group) PUT ¶
func (g *Group) PUT(path string, handlers ...gin.HandlerFunc) *Route
PUT defines a PUT route at path, relative to the group prefix, served by handlers.
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern constrains a path param, see Param on Group and Route. It can only be built from UUID, Numeric, Regex and OneOf.
func OneOf ¶
OneOf is a Param pattern that matches exactly one of values. The values are matched literally, regex metacharacters in them are escaped.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *Registry
func (*Registry) AddExporter ¶
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
func (*Route) IsInternal ¶
func (*Route) Param ¶
Param constrains the named path param of the route, overriding a group pattern for it. The param must be in the route's path.
func (*Route) Params ¶
Params returns the patterns of the params in the route's path, resolved through its groups. Unconstrained params are not included.
func (*Route) PathRegex ¶
PathRegex returns an anchored regex matching the route's path. A param matches its pattern, "[^/]+" when unconstrained, or ".*" for a catch-all.