Bind URL Path Parameters

  1. package main
  2. import "github.com/kataras/iris/v12"
  3. type myParams struct {
  4. Name string `param:"name"`
  5. Age int `param:"age"`
  6. Tail []string `param:"tail"`
  7. }
  8. // All parameters are required, as we already know,
  9. // the router will fire 404 if name or int or tail are missing.
  10. func main() {
  11. app := iris.Default()
  12. app.Get("/{name}/{age:int}/{tail:path}", func(ctx iris.Context) {
  13. var p myParams
  14. if err := ctx.ReadParams(&p); err != nil {
  15. ctx.StopWithError(iris.StatusInternalServerError, err)
  16. return
  17. }
  18. ctx.Writef("myParams: %#v", p)
  19. })
  20. app.Listen(":8088")
  21. }

Request

  1. $ curl -v http://localhost:8080/kataras/27/iris/web/framework