Former-commit-id: 91cc725ac4e8260dabeca0bd6e58717fd6d4287e
This commit is contained in:
Gerasimos (Makis) Maropoulos 2018-10-03 20:40:52 +03:00
commit 5de3fc5790

View File

@ -212,31 +212,32 @@ app.Get("/static_validation/{name:string has([kataras,gerasimos,maropoulos]}", f
```go
func main() {
app := iris.Default()
app := iris.Default()
// This handler will match /user/john but will not match neither /user/ or /user.
app.Get("/user/{name}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
ctx.Writef("Hello %s", name)
})
// This handler will match /user/john but will not match neither /user/ or /user.
app.Get("/user/{name}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
ctx.Writef("Hello %s", name)
})
// This handler will match /users/42
// but will not match
// neither /users or /users/.
app.Get("/users/{id:int64}", func(ctx iris.Context) {
id, _ := ctx.Params().GetUint64("id")
ctx.Writef("User with ID: %d", id)
})
// This handler will match /users/42
// but will not match
// neither /users or /users/.
app.Get("/users/{id:long}", func(ctx iris.Context) {
id, _ := ctx.Params().GetInt64("id")
ctx.Writef("User with ID: %d", id)
})
// However, this one will match /user/john/ and also /user/john/send.
app.Post("/user/{name:string}/{action:path}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
action := ctx.Params().Get("action")
message := name + " is " + action
ctx.WriteString(message)
})
// This handler will match /user/john/send
// but will not match /user/john/
app.Post("/user/{name:string}/{action:path}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
action := ctx.Params().Get("action")
message := name + " is " + action
ctx.WriteString(message)
})
app.Run(iris.Addr(":8080"))
app.Run(iris.Addr(":8080"))
}
```
@ -890,7 +891,7 @@ func main() {
### Testing
Iris offers an incredible support for the [httpexpect](github.com/iris-contrib/httpexpect), a Testing Framework for web applications. However, you are able to use the standard Go's `net/http/httptest` package as well but in this example we will use the `kataras/iris/httptest`.
Iris offers an incredible support for the [httpexpect](https://github.com/iris-contrib/httpexpect), a Testing Framework for web applications. However, you are able to use the standard Go's `net/http/httptest` package as well but in this example we will use the `kataras/iris/httptest`.
```go
package main