From 239e05fe53b524b5e5cbccd56d6963a31094822f Mon Sep 17 00:00:00 2001 From: Ken Wronkiewicz Date: Fri, 30 Sep 2016 10:54:10 -0700 Subject: [PATCH 1/2] Clarify how route variables work. (#151) (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. --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fa79a6b..3cea354 100644 --- a/README.md +++ b/README.md @@ -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. From 910dd3aa3181e73b3605b92f5db7768a460721c1 Mon Sep 17 00:00:00 2001 From: Ken Wronkiewicz Date: Mon, 3 Oct 2016 15:30:11 -0700 Subject: [PATCH 2/2] Remove unnecessary line from example Review comment: setting the header complicates things. --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 3cea354..5f54d48 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,6 @@ The names are used to create a map of route variables which can be retrieved cal ```go 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"]) }