Update README.md
This commit is contained in:
parent
1dba802590
commit
3b94964068
1 changed files with 4 additions and 4 deletions
|
|
@ -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)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue