mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-25 09:24:04 +01:00
20 lines
481 B
Go
20 lines
481 B
Go
package pattern
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// Match checks whether a string matches a pattern
|
|
func Match(pattern, s string) bool {
|
|
if pattern == "*" {
|
|
return true
|
|
}
|
|
// Backslashes break filepath.Match, so we'll remove all of them.
|
|
// This has a pretty significant impact on performance when there
|
|
// are backslashes, but at least it doesn't break filepath.Match.
|
|
s = strings.ReplaceAll(s, "\\", "")
|
|
matched, _ := filepath.Match(pattern, s)
|
|
return matched
|
|
}
|