Skip to content

Commit 2e3a49a

Browse files
committed
repo: add example to readme file
1 parent a2338de commit 2e3a49a

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
`urlpath` provides a way to parse URL path elements using a schema
88

9+
For users of [gorilla/mux](https://github.com/gorilla/mux).
10+
911
### Getting Started
1012

1113
The `urlpath` package can be added to a project by running:
@@ -14,6 +16,36 @@ The `urlpath` package can be added to a project by running:
1416
go get cattlecloud.net/go/urlpath@latest
1517
```
1618

19+
```go
20+
import "cattlecloud.net/go/urlpath"
21+
```
22+
23+
### Examples
24+
25+
##### mux definition
26+
27+
Make use of gorilla's path variables.
28+
29+
```go
30+
router.Handle("/v1/{category}/{name}, newHandler())
31+
```
32+
33+
##### parsing schema
34+
35+
Create a `Schema` and call `Parse` to extract the path variables.
36+
37+
```go
38+
var (
39+
category int
40+
name string
41+
)
42+
43+
err := urlpath.Parse(request, urlpath.Schema {
44+
"category": urlpath.Int(&category),
45+
"name": urlpath.String(&name),
46+
})
47+
```
48+
1749
### License
1850
1951
The `cattlecloud.net/go/urlpath` module is open source under the [BSD](LICENSE) license.

0 commit comments

Comments
 (0)