1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00
Former-commit-id: 2eb94ec0f565b80790784ac55af024429384b3d3
This commit is contained in:
Gerasimos (Makis) Maropoulos
2018-02-08 14:04:39 +02:00
parent 5d62b5d428
commit 9cdae4ee67
18 changed files with 168 additions and 56 deletions

View File

@@ -4,7 +4,40 @@ import "github.com/kataras/iris"
func main() {
app := iris.New()
// or app.Use(before) and app.Done(after).
app.Get("/", before, mainHandler, after)
// Use registers a middleware(prepend handlers) to all party's, and its children that will be registered
// after.
//
// (`app` is the root children so those use and done handlers will be registered everywhere)
app.Use(func(ctx iris.Context) {
println(`before the party's routes and its children,
but this is not applied to the '/' route
because it's registered before the middleware, order matters.`)
ctx.Next()
})
app.Done(func(ctx iris.Context) {
println("this is executed always last, if the previous handler calls the `ctx.Next()`, it's the reverse of `.Use`")
message := ctx.Values().GetString("message")
println("message: " + message)
})
app.Get("/home", func(ctx iris.Context) {
ctx.HTML("<h1> Home </h1>")
ctx.Values().Set("message", "this is the home message, ip: "+ctx.RemoteAddr())
ctx.Next() // call the done handlers.
})
child := app.Party("/child")
child.Get("/", func(ctx iris.Context) {
ctx.Writef(`this is the localhost:8080/child route.
All Use and Done handlers that are registered to the parent party,
are applied here as well.`)
ctx.Next() // call the done handlers.
})
app.Run(iris.Addr(":8080"))
}