mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
Update to 8.0.2. Read HISTORY.md for the surpise
Former-commit-id: bbdf020ccaa986c332716aa7f749b7bdc24e427e
This commit is contained in:
61
_examples/routing/dynamic-path/root-wildcard/main.go
Normal file
61
_examples/routing/dynamic-path/root-wildcard/main.go
Normal file
@@ -0,0 +1,61 @@
|
||||
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())
|
||||
}
|
||||
Reference in New Issue
Block a user