From 5752625c8048a636778b7acf74914ae9d36ccd92 Mon Sep 17 00:00:00 2001 From: kataras Date: Sat, 15 Jul 2017 17:40:29 +0300 Subject: [PATCH] Update to 8.0.2. Read HISTORY.md for the surpise Former-commit-id: bbdf020ccaa986c332716aa7f749b7bdc24e427e --- HISTORY.md | 83 ++++++++ README.md | 9 +- _examples/README.md | 39 +++- .../single-page-application/basic/main.go | 2 + .../embedded-single-page-application/main.go | 2 + .../dynamic-path/root-wildcard/main.go | 61 ++++++ core/router/handler.go | 31 ++- core/router/node/node.go | 127 +++++++++++-- core/router/router_wildcard_root_test.go | 179 ++++++++++++++++++ doc.go | 2 +- httptest/httptest.go | 2 +- iris.go | 2 +- 12 files changed, 508 insertions(+), 31 deletions(-) create mode 100644 _examples/routing/dynamic-path/root-wildcard/main.go create mode 100644 core/router/router_wildcard_root_test.go diff --git a/HISTORY.md b/HISTORY.md index 03b858af..c3c3d00c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -17,6 +17,89 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene **How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`. +# Su, 15 July 2017 | v8.0.2 + +Okay my friends, this is a good time to upgrade, I did implement a feature that you were asking many times at the past. + +Iris' router can now handle root-level wildcard paths `app.Get("/{paramName:path})`. + +In case you're wondering: no it does not conflict with other static or dynamic routes, meaning that you can code something like this: + +```go +// it isn't conflicts with the rest of the static routes or dynamic routes with a path prefix. +app.Get("/{pathParamName:path}", myHandler) +``` + +Or even like this: + +```go +package main + +import ( + "github.com/kataras/iris" + "github.com/kataras/iris/context" +) + +func main() { + app := iris.New() + + // this works as expected now, + // will handle all GET requests + // except: + // / -> because of app.Get("/", ...) + // /other/anything/here -> because of app.Get("/other/{paramother:path}", ...) + // /other2/anything/here -> because of app.Get("/other2/{paramothersecond:path}", ...) + // /other2/static -> because of app.Get("/other2/static", ...) + // + // It isn't conflicts with the rest of the routes, without routing performance cost! + // + // i.e /something/here/that/cannot/be/found/by/other/registered/routes/order/not/matters + app.Get("/{p:path}", h) + + // this will handle only GET / + app.Get("/", staticPath) + + // this will handle all GET requests starting with "/other/" + // + // i.e /other/more/than/one/path/parts + app.Get("/other/{paramother:path}", other) + + // this will handle all GET requests starting with "/other2/" + // except /other2/static (because of the next static route) + // + // i.e /other2/more/than/one/path/parts + app.Get("/other2/{paramothersecond:path}", other2) + + // this will handle only GET /other2/static + app.Get("/other2/static", staticPath) + + app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed)) +} + +func h(ctx context.Context) { + param := ctx.Params().Get("p") + ctx.WriteString(param) +} + +func other(ctx context.Context) { + param := ctx.Params().Get("paramother") + ctx.Writef("from other: %s", param) +} + +func other2(ctx context.Context) { + param := ctx.Params().Get("paramothersecond") + ctx.Writef("from other2: %s", param) +} + +func staticPath(ctx context.Context) { + ctx.Writef("from the static path: %s", ctx.Path()) +} +``` + +If you find any bugs with this change please send me a [chat message](https://kataras.rocket.chat/channel/iris) in order to investigate it, I'm totally free at weekends. + +Have fun and don't forget to [star](https://github.com/kataras/iris/stargazers) the github repository, it gives me power to continue publishing my work! + # Th, 13 July 2017 | v8.0.1 Nothing tremendous at this minor version. diff --git a/README.md b/README.md index 6406da05..2c60a9ae 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,7 @@ Web applications powered by Iris run everywhere, even [from an android device](h [![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/tree/master/_examples) [![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris) -

-Third-party source for transparency. -

- +