renamed patternmatch.Pattern.Match() to patternmatch.Pattern.Find()

master
Charles Iliya Krempeaux 2019-06-20 21:51:32 -07:00
parent 3cd972d790
commit aa21183e6a
7 changed files with 15 additions and 20 deletions

View File

@ -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

View File

@ -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:

4
doc.go
View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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 {