From aa21183e6aad3b10ef7100cece5a014ee92a8dbe Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Thu, 20 Jun 2019 21:51:32 -0700 Subject: [PATCH] renamed patternmatch.Pattern.Match() to patternmatch.Pattern.Find() --- README.md | 2 +- bad_request.go | 12 ++++++------ doc.go | 4 ++-- pattern.go | 4 ++-- pattern_find.go | 7 +------ pattern_load.go | 2 +- pattern_match_test.go | 4 ++-- 7 files changed, 15 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 7f7be05..2008b0d 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ if nil != err { var userId string var vehicleId string -didMatch, err := pattern.Match("/users/bMM_kJFMEV/vehicles/o_bcU.RZGK", &userId, &vehicleId) +didMatch, err := pattern.Find("/users/bMM_kJFMEV/vehicles/o_bcU.RZGK", &userId, &vehicleId) if nil != err { //@TODO diff --git a/bad_request.go b/bad_request.go index a38280c..d64d374 100644 --- a/bad_request.go +++ b/bad_request.go @@ -6,7 +6,7 @@ package pathmatch // // For example, maybe the uncompiled pattern passed to the pathmatch.Compile() func had // a syntax error in it. Or, also for example, maybe the type of parameter passed to -// pathmatch.Pattern.Match() was of the wrong type. Etc. +// pathmatch.Pattern.Find() was of the wrong type. Etc. // // Example usage of BadRequest with pathmatch.Compile(): // @@ -32,10 +32,10 @@ package pathmatch // } // // Somewhat continuing this example (although without the error in the uncompiled pattern), we might then -// use the pathmatch.Pattern.Match() method, which could also generate an error that fits the BadRequest +// use the pathmatch.Pattern.Find() method, which could also generate an error that fits the BadRequest // interface. // -// Example usage of BadRequest with pathmatch.Pattern.Match(): +// Example usage of BadRequest with pathmatch.Pattern.Find(): // // pattern, err := pathmatch.Compile("/users/{user_id}/cards/{fruit_id}") // if nil != err { @@ -61,18 +61,18 @@ package pathmatch // var userId string // var cardId string // -// didMatch, err := pattern.Match("/users/8sN.oP/cards/X3j_T4", userId, cardId) +// didMatch, err := pattern.Find("/users/8sN.oP/cards/X3j_T4", userId, cardId) // if nil != err { // switch err.(type) { // ← Note that we are using a Go type-switch here. // // case pathmatch.BadRequest: // ← Here we are detecting if the error returned is a pathmatch.BadRequest. // -// fmt.Printf("Something you did when you called pattern.Match() caused an error. The error message was....\n%s\n", err.Error()) +// fmt.Printf("Something you did when you called pattern.Find() caused an error. The error message was....\n%s\n", err.Error()) // return // // case pathmatch.InternalError: // -// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pattern.Match() was running. The error message was....\n%s\n", err.Error()) +// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pattern.Find() was running. The error message was....\n%s\n", err.Error()) // return // // default: diff --git a/doc.go b/doc.go index b82cca8..3e137c0 100644 --- a/doc.go +++ b/doc.go @@ -3,7 +3,7 @@ Package pathmatch provides pattern matching for paths. For example, a path could be a file system path, or a path could be a path from a URL (such as an HTTP or HTTPS based URL). -The matches can be loaded into variables (when using pathmatch.Match()); +The matches can be loaded into variables (when using pathmatch.Find()); or can be loaded into a struct (when using pathmatch.Pattern.MatchAndLoad()). Example Usage: @@ -16,7 +16,7 @@ Example Usage: var userId string var vehicleId string - didMatch, err := pattern.Match("/users/bMM_kJFMEV/vehicles/o_bcU.RZGK", &userId, &vehicleId) + didMatch, err := pattern.Find("/users/bMM_kJFMEV/vehicles/o_bcU.RZGK", &userId, &vehicleId) if nil != err { //@TODO diff --git a/pattern.go b/pattern.go index ae70c20..6c17f74 100644 --- a/pattern.go +++ b/pattern.go @@ -21,7 +21,7 @@ import ( // // var userId string // -// didMatch, err := pattern.Match("/users/123", userId) +// didMatch, err := pattern.Find("/users/123", userId) // if nil != err { // fmt.Printf("ERROR Matching: %v\n", err) // return @@ -34,7 +34,7 @@ import ( // } type Pattern interface { Glob() string - Match(string, ...interface{}) (bool, error) + Find(string, ...interface{}) (bool, error) MatchAndLoad(string, interface{}) (bool, error) MatchNames() []string } diff --git a/pattern_find.go b/pattern_find.go index 2cd5533..1549049 100644 --- a/pattern_find.go +++ b/pattern_find.go @@ -1,22 +1,18 @@ package pathmatch - import ( "strings" ) - const ( doesNotMatter = false ) - var ( errThisShouldNeverHappen = newInternalError("This should never happen.") ) - -func (pattern *internalPattern) Match(path string, args ...interface{}) (bool, error) { +func (pattern *internalPattern) Find(path string, args ...interface{}) (bool, error) { s := path @@ -51,6 +47,5 @@ func (pattern *internalPattern) Match(path string, args ...interface{}) (bool, e } - return true, nil } diff --git a/pattern_load.go b/pattern_load.go index 162fb58..85ab349 100644 --- a/pattern_load.go +++ b/pattern_load.go @@ -24,7 +24,7 @@ func (pattern *internalPattern) MatchAndLoad(path string, strct interface{}) (bo args = append(args, new(string)) } - didMatch, err := pattern.Match(path, args...) + didMatch, err := pattern.Find(path, args...) if nil != err { return doesNotMatter, err } diff --git a/pattern_match_test.go b/pattern_match_test.go index a8ef22e..b2bdbde 100644 --- a/pattern_match_test.go +++ b/pattern_match_test.go @@ -6,7 +6,7 @@ import ( ) -func TestMatch(t *testing.T) { +func TestFind(t *testing.T) { tests := []struct{ Pattern Pattern @@ -105,7 +105,7 @@ func TestMatch(t *testing.T) { } } - if didMatch, err := test.Pattern.Match(test.Path, test.Args...); nil != err { + if didMatch, err := test.Pattern.Find(test.Path, test.Args...); nil != err { t.Errorf("For test #%d, did not expected an error, but actually got one: %v", testNumber, err) continue } else if !didMatch {