Skip to content

Commit

Permalink
lib/path: add example for [Route.Parse]
Browse files Browse the repository at this point in the history
  • Loading branch information
shuLhan committed Jan 24, 2024
1 parent a055c87 commit d686dc5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/path/route_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@ import (
libpath "github.com/shuLhan/share/lib/path"
)

func ExampleRoute_Parse() {
var (
rute *libpath.Route
err error
)

rute, err = libpath.NewRoute(`/book/:title/:page`)
if err != nil {
log.Fatal(err)
}

var (
vals map[string]string
ok bool
)

vals, ok = rute.Parse(`/book/Hitchiker to Galaxy/42`)
fmt.Println(ok, vals)

vals, ok = rute.Parse(`/book/Hitchiker to Galaxy`)
fmt.Println(ok, vals)

vals, ok = rute.Parse(`/book/Hitchiker to Galaxy/42/order`)
fmt.Println(ok, vals)

// Output:
// true map[page:42 title:hitchiker to galaxy]
// false map[]
// false map[]
}

func ExampleRoute_Set() {
var (
rute *libpath.Route
Expand Down

0 comments on commit d686dc5

Please sign in to comment.