@@ -224,20 +224,20 @@ fmt.Printf("%#v\n", tokens[2])
224224Path-To-RegExp exposes a compile function for transforming a string into a valid path.
225225
226226``` go
227+ falseValue := false
227228toPath := pathToRegexp.MustCompile (" /user/:id" , nil )
228229
229230toPath (map [string ]int {" id" : 123 }, nil ) // => "/user/123"
230231toPath (map [string ]string {" id" : " café" }, nil ) // => "/user/caf%C3%A9"
231232toPath (map [string ]string {" id" : " /" }, nil ) // => "/user/%2F"
232233
233234toPath (map [string ]string {" id" : " :/" }, nil ) // => "/user/%3A%2F"
234- toPath (map [string ]string {" id" : " :&" }, &Options{encode: func (value string , token interface {}) string {
235- return value
236- }}) // => panic
237- toPath (map [string ]string {" id" : " :&" }, nil ) // => "/user/%3A%26"
238- toPath (map [string ]string {" id" : " :&" }, &Options{encode: func (value string , token interface {}) string {
239- return value
240- }}) // => /user/:&
235+ toPath (map [string ]string {" id" : " :/" }, &Options{
236+ Encode : func (value string , token interface {}) string {
237+ return value
238+ },
239+ Validate : &falseValue,
240+ }) // => "/user/:/"
241241
242242toPathRepeated := pathToRegexp.MustCompile (" /:segment+" , nil )
243243
@@ -249,8 +249,7 @@ toPathRegexp := pathToRegexp.MustCompile("/user/:id(\\d+)", nil)
249249toPathRegexp (map [string ]int {" id" : 123 }, nil ) // => "/user/123"
250250toPathRegexp (map [string ]string {" id" : " 123" }, nil ) // => "/user/123"
251251toPathRegexp (map [string ]string {" id" : " abc" }, nil ) // => panic
252- t1 := true
253- toPathRegexp (map [string ]string {" id" : " abc" }, &Options{validate: &t1}) // => panic
252+ toPathRegexp (map [string ]string {" id" : " abc" }, &Options{Validate: &falseValue}) // => "/user/abc"
254253```
255254
256255** Note:** The generated function will panic on invalid input. It will do all necessary checks to ensure the generated path is valid. This method only works with strings.
0 commit comments