mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 13:05:56 +00:00
complete the versioning/README.md and add AllowMethods like the normal Party, version-specific middlewares are not needed because the end-developer should declare a middleware with manual matching of version using versioning.Match(ctx, version) bool instead
Former-commit-id: 4f4c23dd7c043d5ab735070ae4d59ea84e3af2e0
This commit is contained in:
@@ -17,8 +17,9 @@ type (
|
||||
}
|
||||
|
||||
Group struct {
|
||||
version string
|
||||
routes []vroute
|
||||
version string
|
||||
extraMethods []string
|
||||
routes []vroute
|
||||
|
||||
deprecation DeprecationOptions
|
||||
}
|
||||
@@ -46,21 +47,40 @@ func (g *Group) Deprecated(options DeprecationOptions) *Group {
|
||||
return g
|
||||
}
|
||||
|
||||
// Handle registers a versioned route to the group.
|
||||
//
|
||||
// See `Concat` and `RegisterGroups` for more.
|
||||
func (g *Group) Handle(method string, registeredPath string, handler context.Handler) {
|
||||
if g.deprecation.ShouldHandle() { // if `Deprecated` called first.
|
||||
handler = Deprecated(handler, g.deprecation)
|
||||
func (g *Group) AllowMethods(methods ...string) *Group {
|
||||
g.extraMethods = append(g.extraMethods, methods...)
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *Group) addVRoute(method, path string, handler context.Handler) {
|
||||
for _, r := range g.routes { // check if already exists.
|
||||
if r.method == method && r.path == path {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
g.routes = append(g.routes, vroute{
|
||||
method: method,
|
||||
path: registeredPath,
|
||||
path: path,
|
||||
versions: Map{g.version: handler},
|
||||
})
|
||||
}
|
||||
|
||||
// Handle registers a versioned route to the group.
|
||||
//
|
||||
// See `Concat` and `RegisterGroups` for more.
|
||||
func (g *Group) Handle(method string, path string, handler context.Handler) {
|
||||
if g.deprecation.ShouldHandle() { // if `Deprecated` called first.
|
||||
handler = Deprecated(handler, g.deprecation)
|
||||
}
|
||||
|
||||
methods := append(g.extraMethods, method)
|
||||
|
||||
for _, method := range methods {
|
||||
g.addVRoute(method, path, handler)
|
||||
}
|
||||
}
|
||||
|
||||
// None registers an "offline" versioned route
|
||||
// see `context#ExecRoute(routeName)` and routing examples.
|
||||
func (g *Group) None(path string, handler context.Handler) {
|
||||
|
||||
Reference in New Issue
Block a user