Update README.md
Example of Catch-All parameters.
This commit is contained in:
parent
545101811a
commit
6c8c90115d
@ -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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user