You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 regels
658 B

  1. package main
  2. import (
  3. "github.com/kataras/iris"
  4. )
  5. func main() {
  6. app := iris.New()
  7. app.Get("/", before, mainHandler, after)
  8. app.Run(iris.Addr(":8081"))
  9. }
  10. func before(ctx iris.Context) {
  11. shareInfo := "this is a shareInfo between handlers"
  12. requestPath := ctx.Path()
  13. println("Before the mainHandler: " + requestPath)
  14. ctx.Values().Set("info", shareInfo)
  15. ctx.Next() //继续下一个handler
  16. }
  17. func after(ctx iris.Context) {
  18. println("after the mainHandler")
  19. }
  20. func mainHandler(ctx iris.Context) {
  21. println("Inside mainHandler")
  22. info := ctx.Values().GetString("info")
  23. ctx.HTML("<h1>Response</h1>")
  24. ctx.HTML("<br/> Info: " + info)
  25. ctx.Next()
  26. }