Update README.md
This commit is contained in:
@@ -52,22 +52,22 @@ r := sux.New()
|
|||||||
// Named parameters
|
// Named parameters
|
||||||
r.GET("/users/:id", func(w http.ResponseWriter, r *http.Request) {
|
r.GET("/users/:id", func(w http.ResponseWriter, r *http.Request) {
|
||||||
params := sux.ParamsFromContext(r)
|
params := sux.ParamsFromContext(r)
|
||||||
id := params["id"]
|
id := params.Get("id")
|
||||||
io.WriteString(w, "User ID: "+id)
|
io.WriteString(w, "User ID: "+id)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Wildcard parameters (captures rest of path)
|
// Wildcard parameters (captures rest of path)
|
||||||
r.GET("/files/*path", func(w http.ResponseWriter, r *http.Request) {
|
r.GET("/files/*path", func(w http.ResponseWriter, r *http.Request) {
|
||||||
params := sux.ParamsFromContext(r)
|
params := sux.ParamsFromContext(r)
|
||||||
path := params["path"]
|
path := params.Get("path")
|
||||||
io.WriteString(w, "File path: "+path)
|
io.WriteString(w, "File path: "+path)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Multiple parameters
|
// Multiple parameters
|
||||||
r.GET("/users/:userId/posts/:postId", func(w http.ResponseWriter, r *http.Request) {
|
r.GET("/users/:userId/posts/:postId", func(w http.ResponseWriter, r *http.Request) {
|
||||||
params := sux.ParamsFromContext(r)
|
params := sux.ParamsFromContext(r)
|
||||||
userId := params["userId"]
|
userId := params.Get("userId")
|
||||||
postId := params["postId"]
|
postId := params.Get("postId")
|
||||||
io.WriteString(w, "User "+userId+", Post "+postId)
|
io.WriteString(w, "User "+userId+", Post "+postId)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user