processor_not_match.go 691 B

1234567891011121314151617181920212223242526272829303132333435
  1. package executor
  2. import (
  3. "fmt"
  4. "regexp"
  5. "strings"
  6. schemepkg "git.buran.team/main/cep/scheme"
  7. )
  8. type NotMatchProcessor struct {
  9. expression *regexp.Regexp
  10. }
  11. func NewNotMatchProcessor(processorScheme schemepkg.Processor) (*NotMatchProcessor, error) {
  12. e, err := regexp.Compile(processorScheme.KindNotMatch.Expression)
  13. if err != nil {
  14. return nil, fmt.Errorf("can't create not-match processor: %w", err)
  15. }
  16. return &NotMatchProcessor{
  17. expression: e,
  18. }, nil
  19. }
  20. func (this *NotMatchProcessor) Process(buffer []byte) bool {
  21. lines := strings.Split(string(buffer), "\n")
  22. for _, line := range lines {
  23. if this.expression.Match([]byte(line)) {
  24. return false
  25. }
  26. }
  27. return true
  28. }