up approve matcher
This commit is contained in:
1 parent
3d97f3789a
commit
1a46b678ef
2 files changed
+11
-5
No files matched your search
@@ -7,17 +7,17 @@ import (
|
||||
var (
|
||||
patterns = []string{
|
||||
"mdm-master/group/method",
|
||||
"mdm-master/group/",
|
||||
"mdm-master/group/*",
|
||||
"mdm-master/group2/method",
|
||||
"mdm-master/group3/",
|
||||
"mdm-master/group3/*",
|
||||
}
|
||||
cases = []struct {
|
||||
method string
|
||||
length int
|
||||
}{
|
||||
{method: "mdm-master/group/method", length: 2},
|
||||
{method: "mdm-master/group/method2", length: 2},
|
||||
{method: "mdm-master/group2/method3", length: 1},
|
||||
{method: "mdm-master/group/method2", length: 1},
|
||||
{method: "mdm-master/group2/method3", length: 0},
|
||||
{method: "mdm-master/group2/method", length: 1},
|
||||
{method: "mdm-master/group3/some", length: 1},
|
||||
{method: "mdm-master/group3/", length: 1},
|
||||
|
||||
@@ -11,7 +11,13 @@ type runtimeMatcher struct {
|
||||
func (mm runtimeMatcher) Match(method string) []string {
|
||||
resp := make([]string, 0)
|
||||
for _, pattern := range mm.patterns {
|
||||
if strings.HasPrefix(method, pattern) {
|
||||
patternLen := len(pattern)
|
||||
if patternLen > 0 && pattern[patternLen-1] == '*' {
|
||||
pattern = pattern[:patternLen-1]
|
||||
if strings.HasPrefix(method, pattern) {
|
||||
resp = append(resp, pattern)
|
||||
}
|
||||
} else if strings.EqualFold(method, pattern) {
|
||||
resp = append(resp, pattern)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user