2022-02-20 11:33:47 +01:00
|
|
|
package writers
|
2022-02-22 08:47:03 +01:00
|
|
|
|
2022-03-05 17:21:46 +01:00
|
|
|
import "StoreBackEnd/pkg/protocol"
|
2022-02-22 08:47:03 +01:00
|
|
|
|
2022-03-08 10:25:00 +01:00
|
|
|
// HelloRulePrefix Rule command prefix
|
|
|
|
const HelloRulePrefix = "HELLO"
|
2022-02-22 08:47:03 +01:00
|
|
|
|
2022-03-08 10:25:00 +01:00
|
|
|
// HelloRule Storage structure for the HelloRule
|
2022-02-22 08:47:03 +01:00
|
|
|
type HelloRule struct {
|
2022-03-08 10:25:00 +01:00
|
|
|
// cmd Rule name
|
|
|
|
cmd string
|
|
|
|
// matcher Allow to make a regex match
|
2022-02-22 08:47:03 +01:00
|
|
|
matcher *protocol.RegexMatcher
|
|
|
|
}
|
|
|
|
|
2022-03-08 10:25:00 +01:00
|
|
|
// CreateHelloRule Creating an instance of HelloRule
|
2022-02-22 09:35:44 +01:00
|
|
|
func CreateHelloRule(pattern string) protocol.IProtocolWriter {
|
2022-02-22 08:47:03 +01:00
|
|
|
return &HelloRule{
|
2022-03-08 10:25:00 +01:00
|
|
|
cmd: HelloRulePrefix,
|
2022-02-22 08:47:03 +01:00
|
|
|
matcher: protocol.CreateRegexMatcher(pattern),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-08 10:25:00 +01:00
|
|
|
// GetCmd retrieve the command name.
|
2022-02-22 08:47:03 +01:00
|
|
|
func (rule HelloRule) GetCmd() string {
|
2022-03-08 10:25:00 +01:00
|
|
|
return rule.cmd
|
2022-02-22 08:47:03 +01:00
|
|
|
}
|
|
|
|
|
2022-03-08 10:25:00 +01:00
|
|
|
// Execute the Rule with a string command.
|
2022-03-12 15:57:27 +01:00
|
|
|
func (rule HelloRule) Execute(argsData ...string) *protocol.ProtocolWriterResult {
|
|
|
|
cmd, _ := rule.matcher.Build(HelloRulePrefix, argsData...)
|
|
|
|
|
|
|
|
return &protocol.ProtocolWriterResult{
|
|
|
|
Cmd: cmd,
|
|
|
|
}
|
2022-02-22 08:47:03 +01:00
|
|
|
}
|