🔨 fix mount tree build

Co-Authored-By: RW <7063188+ReneWerner87@users.noreply.github.com>
pull/830/head
Fenny 2020-09-26 13:46:14 +02:00
parent 753391b217
commit 3b5997a3df
2 changed files with 16 additions and 17 deletions

View File

@ -257,19 +257,20 @@ func Test_App_Nested_Params(t *testing.T) {
utils.AssertEqual(t, 200, resp.StatusCode, "Status code") utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
} }
// func Test_App_Use_App(t *testing.T) { // go test -run Test_App_Mount
// micro := New() func Test_App_Mount(t *testing.T) {
// micro.Get("/doe", func(c *Ctx) error { micro := New()
// return c.SendStatus(StatusOK) micro.Get("/doe", func(c *Ctx) error {
// }) return c.SendStatus(StatusOK)
})
// app := New() app := New()
// app.Use("/john", micro) app.Mount("/john", micro)
// resp, err := app.Test(httptest.NewRequest("GET", "/john/doe", nil)) resp, err := app.Test(httptest.NewRequest("GET", "/john/doe", nil))
// utils.AssertEqual(t, nil, err, "app.Test(req)") utils.AssertEqual(t, nil, err, "app.Test(req)")
// utils.AssertEqual(t, 200, resp.StatusCode, "Status code") utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
// } }
func Test_App_Use_Params(t *testing.T) { func Test_App_Use_Params(t *testing.T) {
app := New() app := New()

View File

@ -16,8 +16,6 @@ import (
// Router defines all router handle interface includes app and group router. // Router defines all router handle interface includes app and group router.
type Router interface { type Router interface {
Mount(prefix string, fiber *App) Router
Use(args ...interface{}) Router Use(args ...interface{}) Router
Get(path string, handlers ...Handler) Router Get(path string, handlers ...Handler) Router
@ -35,6 +33,8 @@ type Router interface {
All(path string, handlers ...Handler) Router All(path string, handlers ...Handler) Router
Group(prefix string, handlers ...Handler) Router Group(prefix string, handlers ...Handler) Router
Mount(prefix string, fiber *App) Router
} }
// Route is a struct that holds all metadata for each registered handler // Route is a struct that holds all metadata for each registered handler
@ -275,8 +275,6 @@ func (app *App) register(method, pathRaw string, handlers ...Handler) Router {
// Add route to stack // Add route to stack
app.addRoute(method, &route) app.addRoute(method, &route)
} }
// Build router tree
app.buildTree()
return app return app
} }
@ -385,8 +383,6 @@ func (app *App) registerStatic(prefix, root string, config ...Static) Router {
app.addRoute(MethodGet, &route) app.addRoute(MethodGet, &route)
// Add HEAD route // Add HEAD route
app.addRoute(MethodHead, &route) app.addRoute(MethodHead, &route)
// Build router tree
app.buildTree()
return app return app
} }
@ -409,6 +405,8 @@ func (app *App) addRoute(method string, route *Route) {
// Add route to the stack // Add route to the stack
app.stack[m] = append(app.stack[m], route) app.stack[m] = append(app.stack[m], route)
} }
// Build router tree
app.buildTree()
} }
// buildTree build the prefix tree from the previously registered routes // buildTree build the prefix tree from the previously registered routes