-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Kilemonn/add-matches-condition
Add matches condition
- Loading branch information
Showing
5 changed files
with
61 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package condition_action | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
type MatchesConditionAction struct { | ||
regex *regexp.Regexp | ||
} | ||
|
||
func NewMatchesConditionAction(id string, pattern string) MatchesConditionAction { | ||
regex, err := regexp.Compile(pattern) | ||
if err != nil { | ||
fmt.Printf("Failed to initialise [Matches] condition's pattern with ID [%s], pattern [%s] with error [%s]. All condition checks will fail.", id, pattern, err.Error()) | ||
} | ||
|
||
return MatchesConditionAction{ | ||
regex: regex, | ||
} | ||
} | ||
|
||
func (a MatchesConditionAction) CheckCondition(input string, args []string) bool { | ||
if a.regex == nil { | ||
return false | ||
} | ||
return a.regex.Match([]byte(input)) | ||
} |
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