summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-01-25 00:48:28 +0700
committerShulhan <ms@kilabit.info>2024-01-25 00:49:16 +0700
commitd686dc52c221360295c4b48a987329abe624e4fa (patch)
tree1acea98e2c8f7f96d336607c005fa0deb72165e2
parenta055c87a24417dbc6760224ad9dcfb204751e702 (diff)
downloadpakakeh.go-d686dc52c221360295c4b48a987329abe624e4fa.tar.xz
lib/path: add example for [Route.Parse]
-rw-r--r--lib/path/route_example_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/path/route_example_test.go b/lib/path/route_example_test.go
index d97603c1..6d7c6380 100644
--- a/lib/path/route_example_test.go
+++ b/lib/path/route_example_test.go
@@ -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