2022-03-08 10:25:00 +01:00
|
|
|
package writers
|
|
|
|
|
2022-03-12 15:57:27 +01:00
|
|
|
import (
|
|
|
|
"StoreBackEnd/pkg/protocol"
|
|
|
|
)
|
2022-03-08 10:25:00 +01:00
|
|
|
|
|
|
|
// 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.
|
2022-03-12 15:57:27 +01:00
|
|
|
func (rule SendErrorRule) Execute(argsData ...string) *protocol.ProtocolWriterResult {
|
|
|
|
buildedCmd, _ := rule.matcher.Build(SendErrorRulePrefix, argsData...)
|
|
|
|
|
|
|
|
return &protocol.ProtocolWriterResult{
|
|
|
|
Cmd: buildedCmd,
|
|
|
|
}
|
2022-03-08 10:25:00 +01:00
|
|
|
}
|