From 64422ea7ec1b60473c5438b26bac7e4b1ec8d77e Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Mon, 24 Jun 2019 14:05:08 -0700 Subject: [PATCH] pathmatch.Pattern.String() --- example_pattern_string_test.go | 26 ++++++++++++++++++++++++++ pattern.go | 1 + pattern_string.go | 8 ++++++++ 3 files changed, 35 insertions(+) create mode 100644 example_pattern_string_test.go create mode 100644 pattern_string.go diff --git a/example_pattern_string_test.go b/example_pattern_string_test.go new file mode 100644 index 0000000..8ced072 --- /dev/null +++ b/example_pattern_string_test.go @@ -0,0 +1,26 @@ +package pathmatch_test + +import ( + "github.com/reiver/go-pathmatch" + + "fmt" + "os" +) + +func ExamplePatternString() { + + var template = "/v1/users/{user_id}" + + var pattern pathmatch.Pattern + + err := pathmatch.CompileTo(&pattern, template) + if nil != err { + fmt.Fprintf(os.Stderr, "ERROR: %s\n", err) + return + } + + fmt.Printf("pattern: %s", pattern) + + // Output: + // pattern: /v1/users/{user_id} +} diff --git a/pattern.go b/pattern.go index 16b900f..41dda30 100644 --- a/pattern.go +++ b/pattern.go @@ -32,6 +32,7 @@ import ( // } type Pattern struct { mutex sync.RWMutex + template string bits []string names []string namesSet map[string]struct{} diff --git a/pattern_string.go b/pattern_string.go new file mode 100644 index 0000000..df07139 --- /dev/null +++ b/pattern_string.go @@ -0,0 +1,8 @@ +package pathmatch + +// String makes pathmatch.Pattern fit the fmt.Stringer interface. +// +// String returns the (pre-compiled) pattern template. +func (receiver Pattern) String() string { + return receiver.template +}