diff --git a/app.go b/app.go index 6b5eb0cd..8c552545 100644 --- a/app.go +++ b/app.go @@ -1,5 +1,5 @@ // ⚡️ Fiber is an Express inspired web framework written in Go with ☕️ -// 📝 Github Repository: https://github.com/gofiber/fiber +// 🤖 Github Repository: https://github.com/gofiber/fiber // 📌 API Documentation: https://docs.gofiber.io package fiber diff --git a/app_test.go b/app_test.go index f71ae6ec..3248e851 100644 --- a/app_test.go +++ b/app_test.go @@ -1,11 +1,7 @@ // ⚡️ Fiber is an Express inspired web framework written in Go with ☕️ -// 📝 Github Repository: https://github.com/gofiber/fiber +// 🤖 Github Repository: https://github.com/gofiber/fiber // 📌 API Documentation: https://docs.gofiber.io -// go test -v -coverprofile cover.out . -// go tool cover -html=cover.out -o cover.html -// open cover.html - package fiber import ( diff --git a/ctx.go b/ctx.go index 8f57c68e..7be06d45 100644 --- a/ctx.go +++ b/ctx.go @@ -1,5 +1,5 @@ // ⚡️ Fiber is an Express inspired web framework written in Go with ☕️ -// 📝 Github Repository: https://github.com/gofiber/fiber +// 🤖 Github Repository: https://github.com/gofiber/fiber // 📌 API Documentation: https://docs.gofiber.io package fiber @@ -624,7 +624,7 @@ func (ctx *Ctx) Params(key string) (value string) { if ctx.route.Params == nil { return } - for i := 0; i < len(ctx.route.Params); i++ { + for i := range ctx.route.Params { if (ctx.route.Params)[i] == key { return ctx.values[i] } diff --git a/ctx_test.go b/ctx_test.go index 67fd7f14..c340e41e 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -1,5 +1,5 @@ // ⚡️ Fiber is an Express inspired web framework written in Go with ☕️ -// 📝 Github Repository: https://github.com/gofiber/fiber +// 🤖 Github Repository: https://github.com/gofiber/fiber // 📌 API Documentation: https://docs.gofiber.io package fiber diff --git a/params.go b/params.go index a3239035..4e71e7de 100644 --- a/params.go +++ b/params.go @@ -30,6 +30,9 @@ var paramsDummy = make([]string, 100, 100) // New ... func parseParams(pattern string) (p parsedParams) { + if pattern[0] != '/' { + pattern = "/" + pattern + } var patternCount int aPattern := []string{""} if pattern != "" { diff --git a/params_test.go b/params_test.go index b69c3257..d0566e92 100644 --- a/params_test.go +++ b/params_test.go @@ -21,6 +21,19 @@ type testCase struct { ok bool } +func Test_With_Starting_Wildcard(t *testing.T) { + checkCases( + t, + parseParams("/*"), + []testCase{ + {uri: "/api/v1/entity", params: []string{"api/v1/entity"}, ok: true}, + {uri: "/api/v1/entity/", params: []string{"api/v1/entity/"}, ok: true}, + {uri: "/api/v1/entity/1", params: []string{"api/v1/entity/1"}, ok: true}, + {uri: "/", params: []string{""}, ok: true}, + }, + ) +} + func Test_With_Param_And_Wildcard(t *testing.T) { checkCases( t, @@ -181,17 +194,6 @@ func Test_With_With_Simple_Path(t *testing.T) { }, ) } -func Test_With_With_Empty_Path(t *testing.T) { - checkCases( - t, - parseParams(""), - []testCase{ - {uri: "/api", params: nil, ok: false}, - {uri: "", params: []string{}, ok: true}, - {uri: "/", params: []string{}, ok: true}, - }, - ) -} func Test_With_With_FileName(t *testing.T) { checkCases( diff --git a/router.go b/router.go index c7db0ced..0f9bd7fc 100644 --- a/router.go +++ b/router.go @@ -65,7 +65,7 @@ func (r *Route) matchRoute(path string) (match bool, values []string) { if r.use { // Match any path if route equals '*' or '/' if r.star || r.root { - return true, values + return true, []string{path} } // Middleware matches path prefix if strings.HasPrefix(path, r.Path) { @@ -76,7 +76,7 @@ func (r *Route) matchRoute(path string) (match bool, values []string) { } // '*' wildcard matches any path if r.star { - return true, values + return true, []string{path} } // Check if a single '/' matches if r.root && path == "/" { @@ -191,7 +191,7 @@ func (app *App) registerStatic(prefix, root string, config ...Static) { prefix = "/" } // Prefix always start with a '/' or '*' - if prefix[0] != '/' && prefix[0] != '*' { + if prefix[0] != '/' { prefix = "/" + prefix } // Match anything diff --git a/router_test.go b/router_test.go index e100bd49..c555aca3 100644 --- a/router_test.go +++ b/router_test.go @@ -1,11 +1,6 @@ // ⚡️ Fiber is an Express inspired web framework written in Go with ☕️ -// 📝 Github Repository: https://github.com/gofiber/fiber +// 🤖 Github Repository: https://github.com/gofiber/fiber // 📌 API Documentation: https://docs.gofiber.io -// ⚠️ This path parser was based on urlpath by @ucarion (MIT License). -// 💖 Modified for the Fiber router by @renanbastos93 & @renewerner87 -// 🤖 ucarion/urlpath - renanbastos93/fastpath - renewerner87/fastpath - -// router benchmarks package fiber diff --git a/utils.go b/utils.go index ea93207b..6ac11529 100644 --- a/utils.go +++ b/utils.go @@ -1,5 +1,5 @@ // ⚡️ Fiber is an Express inspired web framework written in Go with ☕️ -// 📝 Github Repository: https://github.com/gofiber/fiber +// 🤖 Github Repository: https://github.com/gofiber/fiber // 📌 API Documentation: https://docs.gofiber.io package fiber