mirror of https://github.com/gofiber/fiber.git
🖇 Cleanup router chaining
parent
ea7429eaf7
commit
f9e6ea8103
6
app.go
6
app.go
|
@ -300,7 +300,7 @@ func (app *App) Use(args ...interface{}) Router {
|
|||
panic(fmt.Sprintf("use: invalid handler %v\n", reflect.TypeOf(arg)))
|
||||
}
|
||||
}
|
||||
_ = app.register(methodUse, prefix, handlers...)
|
||||
app.register(methodUse, prefix, handlers...)
|
||||
return app
|
||||
}
|
||||
|
||||
|
@ -359,13 +359,13 @@ func (app *App) Patch(path string, handlers ...Handler) Router {
|
|||
|
||||
// Add ...
|
||||
func (app *App) Add(method, path string, handlers ...Handler) Router {
|
||||
_ = app.register(method, path, handlers...)
|
||||
app.register(method, path, handlers...)
|
||||
return app
|
||||
}
|
||||
|
||||
// Static ...
|
||||
func (app *App) Static(prefix, root string, config ...Static) Router {
|
||||
_ = app.registerStatic(prefix, root, config...)
|
||||
app.registerStatic(prefix, root, config...)
|
||||
return app
|
||||
}
|
||||
|
||||
|
|
8
group.go
8
group.go
|
@ -35,7 +35,7 @@ func (grp *Group) Use(args ...interface{}) Router {
|
|||
panic(fmt.Sprintf("use: invalid handler %v\n", reflect.TypeOf(arg)))
|
||||
}
|
||||
}
|
||||
_ = grp.app.register(methodUse, getGroupPath(grp.prefix, path), handlers...)
|
||||
grp.app.register(methodUse, getGroupPath(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
|
@ -94,13 +94,13 @@ func (grp *Group) Patch(path string, handlers ...Handler) Router {
|
|||
|
||||
// Add ...
|
||||
func (grp *Group) Add(method, path string, handlers ...Handler) Router {
|
||||
_ = grp.app.register(method, getGroupPath(grp.prefix, path), handlers...)
|
||||
grp.app.register(method, getGroupPath(grp.prefix, path), handlers...)
|
||||
return grp
|
||||
}
|
||||
|
||||
// Static ...
|
||||
func (grp *Group) Static(prefix, root string, config ...Static) Router {
|
||||
_ = grp.app.registerStatic(getGroupPath(grp.prefix, prefix), root, config...)
|
||||
grp.app.registerStatic(getGroupPath(grp.prefix, prefix), root, config...)
|
||||
return grp
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ func (grp *Group) All(path string, handlers ...Handler) Router {
|
|||
func (grp *Group) Group(prefix string, handlers ...Handler) Router {
|
||||
prefix = getGroupPath(grp.prefix, prefix)
|
||||
if len(handlers) > 0 {
|
||||
_ = grp.app.register(methodUse, prefix, handlers...)
|
||||
grp.app.register(methodUse, prefix, handlers...)
|
||||
}
|
||||
return grp.app.Group(prefix)
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ func (app *App) handler(rctx *fasthttp.RequestCtx) {
|
|||
app.ReleaseCtx(ctx)
|
||||
}
|
||||
|
||||
func (app *App) register(method, pathRaw string, handlers ...Handler) *Route {
|
||||
func (app *App) register(method, pathRaw string, handlers ...Handler) {
|
||||
// Uppercase HTTP methods
|
||||
method = utils.ToUpper(method)
|
||||
// Check if the HTTP method is valid unless it's USE
|
||||
|
@ -208,7 +208,7 @@ func (app *App) register(method, pathRaw string, handlers ...Handler) *Route {
|
|||
for _, m := range intMethod {
|
||||
app.addRoute(m, route)
|
||||
}
|
||||
return route
|
||||
return
|
||||
}
|
||||
|
||||
// Handle GET routes on HEAD requests
|
||||
|
@ -218,11 +218,9 @@ func (app *App) register(method, pathRaw string, handlers ...Handler) *Route {
|
|||
|
||||
// Add route to stack
|
||||
app.addRoute(method, route)
|
||||
|
||||
return route
|
||||
}
|
||||
|
||||
func (app *App) registerStatic(prefix, root string, config ...Static) *Route {
|
||||
func (app *App) registerStatic(prefix, root string, config ...Static) {
|
||||
// For security we want to restrict to the current work directory.
|
||||
if len(root) == 0 {
|
||||
root = "."
|
||||
|
@ -323,7 +321,6 @@ func (app *App) registerStatic(prefix, root string, config ...Static) *Route {
|
|||
// Add route to stack
|
||||
app.addRoute(MethodGet, route)
|
||||
app.addRoute(MethodHead, route)
|
||||
return route
|
||||
}
|
||||
|
||||
func (app *App) addRoute(method string, route *Route) {
|
||||
|
|
Loading…
Reference in New Issue