-
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 Negate Support
Signed-off-by: Arthur <[email protected]>
- Loading branch information
1 parent
de76937
commit 17e087b
Showing
3 changed files
with
52 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
package glob | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/gobwas/glob" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func Match(pattern, text string, separators ...rune) bool { | ||
compiledGlob, err := glob.Compile(pattern, separators...) | ||
if err != nil { | ||
log.Warnf("failed to compile pattern %s due to error %v", pattern, err) | ||
return false | ||
if strings.HasPrefix(pattern, "!") { | ||
compiledGlob, err := glob.Compile(pattern[1:], separators...) | ||
if err != nil { | ||
log.Warnf("failed to compile pattern %s due to error %v", pattern, err) | ||
return false | ||
} | ||
return !compiledGlob.Match(text) | ||
} else { | ||
compiledGlob, err := glob.Compile(pattern, separators...) | ||
if err != nil { | ||
log.Warnf("failed to compile pattern %s due to error %v", pattern, err) | ||
return false | ||
} | ||
return compiledGlob.Match(text) | ||
} | ||
return compiledGlob.Match(text) | ||
} |
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