StoreBackEnd/pkg/protocol/rules/writers/SendErrorRule.go
2022-03-20 15:32:45 +01:00

39 lines
940 B
Go

package writers
import (
"StoreBackEnd/pkg/protocol"
)
// SendErrorRulePrefix Rule command prefix
const SendErrorRulePrefix = "SEND_ERROR"
// SendErrorRule Storage structure for the SendErrorRule
type SendErrorRule struct {
// cmd Rule name
cmd string
// matcher Allow to make a regex match
matcher *protocol.RegexMatcher
}
// CreateSendErrorRule Creating an instance of SendErrorRule
func CreateSendErrorRule(pattern string) protocol.IProtocolWriter {
return &SendErrorRule{
cmd: SendErrorRulePrefix,
matcher: protocol.CreateRegexMatcher(pattern),
}
}
// GetCmd retrieve the command name.
func (rule SendErrorRule) GetCmd() string {
return rule.cmd
}
// Execute the Rule with a string command.
func (rule SendErrorRule) Execute(argsData ...string) *protocol.ProtocolWriterResult {
buildedCmd, _ := rule.matcher.Build(SendErrorRulePrefix, argsData...)
return &protocol.ProtocolWriterResult{
Cmd: buildedCmd,
}
}