StoreBackEnd/pkg/protocol/rules/writers/RetrieveErrorRule.go

39 lines
996 B
Go

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