// Register the route...
app.Get("/{name}/{age:int}/{tail:path}", handler)
func handler(ctx iris.Context) {
params := ctx.Params()
name := params.Get("name")
age := params.GetIntDefault("age", 18)
tail := strings.Split(params.Get("tail"), "/")
}
Let's create our Go structure.
type myParams struct {
Name string `param:"name"`
Age int `param:"age"`
Tail []string `param:"tail"`
}
Now, the handler which reads the URL and binds to a "myParams" value.
func handler(ctx iris.Context) {
var p myParams
if err := ctx.ReadParams(&p); err != nil {
ctx.StopWithError(iris.StatusInternalServerError, err)
return
}
}
http://localhost:8080/kataras/27/iris/web/framework
myParams{
Name: "kataras",
Age: 27,
Tail: []string{"iris", "web", "framework"},
}