Skip to content

Commit 933f7c1

Browse files
committed
Fixes #1 better return error, not use panic.
1 parent c5d4298 commit 933f7c1

File tree

3 files changed

+217
-215
lines changed

3 files changed

+217
-215
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ import pathToRegexp "github.com/soongo/path-to-regexp"
5757
- **Validate** When `false` the function can produce an invalid (unmatched) path. (default: `true`)
5858
- **Delimiter** The default delimiter for segments, e.g. `[^/#?]` for `:named` patterns. (default: `'/#?'`)
5959
- **EndsWith** Optional character, or list of characters, to treat as "end" characters.
60-
- **prefixes** List of characters to automatically consider prefixes when parsing. (default: `./`)
60+
- **Prefixes** List of characters to automatically consider prefixes when parsing. (default: `./`)
6161
- **Encode** How to encode uri. (default: `func (uri string, token interface{}) string { return uri }`)
62-
- **Decode** How to decode uri. (default: `func (uri string, token interface{}) string { return uri }`)
62+
- **Decode** How to decode uri. (default: `func (uri string, token interface{}) (string, error) { return uri }`)
6363

6464
```go
6565
var tokens []pathToRegexp.Token
@@ -270,7 +270,7 @@ fmt.Printf("%d %q\n", match.Index, match)
270270
The `match` function will return a function for transforming paths into parameters:
271271

272272
```go
273-
match := pathToRegexp.MustMatch("/user/:id", &pathToRegexp.Options{Decode: func(str string, token interface{}) string {
273+
match := pathToRegexp.MustMatch("/user/:id", &pathToRegexp.Options{Decode: func(str string, token interface{}) (string, error) {
274274
return pathToRegexp.DecodeURIComponent(str)
275275
}})
276276

@@ -288,7 +288,7 @@ match("/user/caf%C3%A9")
288288
The `Parse` function will return a list of strings and tokens from a path string:
289289

290290
```go
291-
tokens := pathToRegexp.Parse("/route/:foo/(.*)", nil)
291+
tokens, _ := pathToRegexp.Parse("/route/:foo/(.*)", nil)
292292

293293
fmt.Printf("%#v\n", tokens[0])
294294
//=> "/route"

0 commit comments

Comments
 (0)