查询字符串
获取URL参数
与其它框架不同,Iris 的url查询字符串并不是显性路由一部分,它隐式由请求对象发起,如下所示
func main() {
app := iris.Default()
// 查询字符串参数用在隐式的请求对象上,被传递
// 请求匹配字符串: /welcome?firstname=Jane&lastname=Doe.
app.Get("/welcome", func(ctx iris.Context) {
firstname := ctx.URLParamDefault("firstname", "Guest")
// 使用 ctx.Request().URL.Query().Get("lastname")调用方法的快捷方式
lastname := ctx.URLParam("lastname")
ctx.Writef("Hello %s %s", firstname, lastname)
})
app.Run(iris.Addr(":8080"))
}