mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
update README.md example (#1084)
* update README.md example * update README.md example Former-commit-id: 5eb484d2204e839e5408d3b8cf98fa0981d4727a
This commit is contained in:
parent
6fc7fc632a
commit
f4e2742dc7
43
README.md
43
README.md
|
@ -212,31 +212,32 @@ app.Get("/static_validation/{name:string has([kataras,gerasimos,maropoulos]}", f
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.Default()
|
app := iris.Default()
|
||||||
|
|
||||||
// This handler will match /user/john but will not match neither /user/ or /user.
|
// This handler will match /user/john but will not match neither /user/ or /user.
|
||||||
app.Get("/user/{name}", func(ctx iris.Context) {
|
app.Get("/user/{name}", func(ctx iris.Context) {
|
||||||
name := ctx.Params().Get("name")
|
name := ctx.Params().Get("name")
|
||||||
ctx.Writef("Hello %s", name)
|
ctx.Writef("Hello %s", name)
|
||||||
})
|
})
|
||||||
|
|
||||||
// This handler will match /users/42
|
// This handler will match /users/42
|
||||||
// but will not match
|
// but will not match
|
||||||
// neither /users or /users/.
|
// neither /users or /users/.
|
||||||
app.Get("/users/{id:int64}", func(ctx iris.Context) {
|
app.Get("/users/{id:long}", func(ctx iris.Context) {
|
||||||
id, _ := ctx.Params().GetUint64("id")
|
id, _ := ctx.Params().GetInt64("id")
|
||||||
ctx.Writef("User with ID: %d", id)
|
ctx.Writef("User with ID: %d", id)
|
||||||
})
|
})
|
||||||
|
|
||||||
// However, this one will match /user/john/ and also /user/john/send.
|
// This handler will match /user/john/send
|
||||||
app.Post("/user/{name:string}/{action:path}", func(ctx iris.Context) {
|
// but will not match /user/john/
|
||||||
name := ctx.Params().Get("name")
|
app.Post("/user/{name:string}/{action:path}", func(ctx iris.Context) {
|
||||||
action := ctx.Params().Get("action")
|
name := ctx.Params().Get("name")
|
||||||
message := name + " is " + action
|
action := ctx.Params().Get("action")
|
||||||
ctx.WriteString(message)
|
message := name + " is " + action
|
||||||
})
|
ctx.WriteString(message)
|
||||||
|
})
|
||||||
|
|
||||||
app.Run(iris.Addr(":8080"))
|
app.Run(iris.Addr(":8080"))
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user