Update README.md

Example of Catch-All parameters.
This commit is contained in:
Javier Provecho 2014-07-08 11:55:20 +02:00
parent 545101811a
commit 6c8c90115d
1 changed files with 5 additions and 3 deletions

View File

@ -84,20 +84,22 @@ func main() {
```go
func main() {
r := gin.Default()
// This handler will match /user/john but will not match neither /user/ or /user
r.GET("/user/:name", func(c *gin.Context) {
name := c.Params.ByName("name")
message := "Hello "+name
c.String(200, message)
})
r.GET("/user/:name/:action", func(c *gin.Context) {
// However, this one will match /user/john and also /user/john/send
r.GET("/user/:name/*action", func(c *gin.Context) {
name := c.Params.ByName("name")
action := c.Params.ByName("action")
message := name + " is " + action
c.String(200, message)
})
// Listen and server on 0.0.0.0:8080
r.Run(":8080")
}