Skip to content

Commit 0941330

Browse files
Dean KarnDean Karn
authored andcommitted
correct README, params extraction documentation was incorrect.
1 parent c9a8702 commit 0941330

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
##Pure
22
<img align="right" src="https://raw.githubusercontent.com/go-playground/pure/master/logo.png">
3-
![Project status](https://img.shields.io/badge/version-3.0.0-green.svg)
3+
![Project status](https://img.shields.io/badge/version-3.0.1-green.svg)
44
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/pure/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/pure)
55
[![Coverage Status](https://coveralls.io/repos/github/go-playground/pure/badge.svg?branch=master)](https://coveralls.io/github/go-playground/pure?branch=master)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/pure)](https://goreportcard.com/report/github.com/go-playground/pure)
@@ -76,10 +76,9 @@ l.Get("/user/:id", UserHandler)
7676

7777
// extract params like so
7878
rv := pure.ReqestVars(r) // done this way so only have to extract from context once, read above
79-
params := rv.Params() or params := pure.ReqestVars(r).Params()
80-
params.Get(paramname)
79+
rv.URLParam(paramname)
8180

82-
// serve css, js etc.. pure.RequestVars(r).Params().Get(pure.WildcardParam) will return the remaining path if
81+
// serve css, js etc.. pure.RequestVars(r).URLParam(pure.WildcardParam) will return the remaining path if
8382
// you need to use it in a custom handler...
8483
l.Get("/static/*", http.FileServer(http.Dir("static/")))
8584

examples/params/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/go-playground/pure"
7+
mw "github.com/go-playground/pure/examples/middleware/logging-recovery"
8+
)
9+
10+
func main() {
11+
12+
p := pure.New()
13+
p.Use(mw.LoggingAndRecovery(true))
14+
15+
p.Get("/user/:id", user)
16+
17+
http.ListenAndServe(":3007", p.Serve())
18+
}
19+
20+
func user(w http.ResponseWriter, r *http.Request) {
21+
rv := pure.RequestVars(r)
22+
23+
w.Write([]byte("USER_ID:" + rv.URLParam("id")))
24+
}

0 commit comments

Comments
 (0)