-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sourceNamespace): Glob -> Regex2 Library
Signed-off-by: Arthur <[email protected]>
- Loading branch information
1 parent
de76937
commit 437e2f0
Showing
7 changed files
with
42 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package regex | ||
|
||
// MatchStringInList will return true if item is contained in list. If | ||
// exactMatch is set to false, list may contain globs to be matched. | ||
func MatchStringInList(list []string, item string, exactMatch bool) bool { | ||
for _, ll := range list { | ||
if item == ll || (!exactMatch && Match(ll, item)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package regex | ||
|
||
import ( | ||
"github.com/dlclark/regexp2" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func Match(pattern, text string) bool { | ||
compiledRegex, err := regexp2.Compile(pattern, 0) | ||
if err != nil { | ||
log.Warnf("failed to compile pattern %s due to error %v", pattern, err) | ||
return false | ||
} | ||
regexMatch, err := compiledRegex.MatchString(text) | ||
if err != nil { | ||
log.Warnf("failed to match pattern %s due to error %v", pattern, err) | ||
return false | ||
} | ||
return regexMatch | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters