Skip to content

Commit

Permalink
Clarify how route variables work. (gorilla#151)
Browse files Browse the repository at this point in the history
(this confused the heck out of me while trying to use Gorilla)

* Changed `request` to be just `r`, like the other handlers.
* Created complete wrapper function instead of just 2 lines.
  • Loading branch information
Ken Wronkiewicz committed Sep 30, 2016
1 parent 757bef9 commit 239e05f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 65,12 @@ r.HandleFunc("/articles/{category}/{id:[0-9] }", ArticleHandler)
The names are used to create a map of route variables which can be retrieved calling `mux.Vars()`:

```go
vars := mux.Vars(request)
category := vars["category"]
func ArticlesCategoryHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Category: %v\n", vars["category"])
}
```

And this is all you need to know about the basic usage. More advanced options are explained below.
Expand Down

0 comments on commit 239e05f

Please sign in to comment.