matchers.go 617 B

123456789101112131415161718192021222324252627282930313233343536
  1. package strmatcher
  2. import (
  3. "regexp"
  4. "strings"
  5. )
  6. type fullMatcher string
  7. func (m fullMatcher) Match(s string) bool {
  8. return string(m) == s
  9. }
  10. type substrMatcher string
  11. func (m substrMatcher) Match(s string) bool {
  12. return strings.Contains(s, string(m))
  13. }
  14. type domainMatcher string
  15. func (m domainMatcher) Match(s string) bool {
  16. pattern := string(m)
  17. if !strings.HasSuffix(s, pattern) {
  18. return false
  19. }
  20. return len(s) == len(pattern) || s[len(s)-len(pattern)-1] == '.'
  21. }
  22. type regexMatcher struct {
  23. pattern *regexp.Regexp
  24. }
  25. func (m *regexMatcher) Match(s string) bool {
  26. return m.pattern.MatchString(s)
  27. }