Ajout des 3règles SendFileRule.go, SendOkRule.go, SendErrorRule.go et corrections de bugs mineurs.
This commit is contained in:
@@ -2,8 +2,8 @@ package readers
|
||||
|
||||
import "StoreBackEnd/pkg/protocol"
|
||||
|
||||
// EraseFileRuleName Identifiant de cette règle
|
||||
const EraseFileRuleName = "ffe_erasefile"
|
||||
// EraseFileRulePrefix Identifiant de cette règle
|
||||
const EraseFileRulePrefix = "ERASEFILE"
|
||||
|
||||
// EraseFileRule Demande de suppression d'un fichier
|
||||
type EraseFileRule struct {
|
||||
@@ -17,7 +17,7 @@ type EraseFileRule struct {
|
||||
// CreateEraseFileRule Création d'une instance de EraseFileRule
|
||||
func CreateEraseFileRule(pattern string) protocol.IProtocolReader {
|
||||
return &EraseFileRule{
|
||||
Cmd: EraseFileRuleName,
|
||||
Cmd: EraseFileRulePrefix,
|
||||
matcher: protocol.CreateRegexMatcher(pattern),
|
||||
}
|
||||
}
|
||||
|
||||
49
pkg/protocol/rules/readers/SendFileRule.go
Normal file
49
pkg/protocol/rules/readers/SendFileRule.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package readers
|
||||
|
||||
import "StoreBackEnd/pkg/protocol"
|
||||
|
||||
// SendFileRulePrefix Rule command prefix
|
||||
const SendFileRulePrefix = "ffe_sendfile"
|
||||
|
||||
// SendFileRule Storage structure for the SendFileRule
|
||||
type SendFileRule struct {
|
||||
// cmd Rule name
|
||||
cmd string
|
||||
// matcher Allow to make a regex match
|
||||
matcher *protocol.RegexMatcher
|
||||
}
|
||||
|
||||
// CreateSendFileRule Creating an instance of SendFileRule
|
||||
func CreateSendFileRule(pattern string) protocol.IProtocolReader {
|
||||
return &SendFileRule{
|
||||
cmd: SendFileRulePrefix,
|
||||
matcher: protocol.CreateRegexMatcher(pattern),
|
||||
}
|
||||
}
|
||||
|
||||
// GetCmd retrieve the command name.
|
||||
func (rule SendFileRule) GetCmd() string {
|
||||
return rule.cmd
|
||||
}
|
||||
|
||||
// Execute the Rule with a string command.
|
||||
func (rule SendFileRule) Execute(data string) (string, bool) {
|
||||
if rule.Match(data) { // TODO : cloture this command.
|
||||
values := rule.matcher.Parse(data)
|
||||
//callback := func() {
|
||||
//
|
||||
//}
|
||||
//callback()
|
||||
println(values[1], " File Name Hash")
|
||||
println(values[2], " File Size")
|
||||
println(values[3], " File Content Hash")
|
||||
return "SEND_OK\r\n", true
|
||||
} else {
|
||||
return "jjdjd", false
|
||||
}
|
||||
}
|
||||
|
||||
// Match make a match with the current Rule and check if it matches.
|
||||
func (rule SendFileRule) Match(data string) bool {
|
||||
return rule.matcher.Match(data)
|
||||
}
|
||||
@@ -2,28 +2,31 @@ package writers
|
||||
|
||||
import "StoreBackEnd/pkg/protocol"
|
||||
|
||||
const HelloRuleName = "sbe_hello"
|
||||
// HelloRulePrefix Rule command prefix
|
||||
const HelloRulePrefix = "HELLO"
|
||||
|
||||
// HelloRule Storage structure for the HelloRule
|
||||
type HelloRule struct {
|
||||
// Cmd Nom de la règle
|
||||
Cmd string
|
||||
|
||||
// matcher Permet d'extraire de éléments d'une chaine
|
||||
// cmd Rule name
|
||||
cmd string
|
||||
// matcher Allow to make a regex match
|
||||
matcher *protocol.RegexMatcher
|
||||
}
|
||||
|
||||
// CreateHelloRule Création d'une instance de HelloRule
|
||||
// CreateHelloRule Creating an instance of HelloRule
|
||||
func CreateHelloRule(pattern string) protocol.IProtocolWriter {
|
||||
return &HelloRule{
|
||||
Cmd: HelloRuleName,
|
||||
cmd: HelloRulePrefix,
|
||||
matcher: protocol.CreateRegexMatcher(pattern),
|
||||
}
|
||||
}
|
||||
|
||||
// GetCmd retrieve the command name.
|
||||
func (rule HelloRule) GetCmd() string {
|
||||
return rule.Cmd
|
||||
return rule.cmd
|
||||
}
|
||||
|
||||
// Execute the Rule with a string command.
|
||||
func (rule HelloRule) Execute(argsData ...string) (string, bool) {
|
||||
return rule.matcher.Build("HELLO", argsData...)
|
||||
return rule.matcher.Build(HelloRulePrefix, argsData...)
|
||||
}
|
||||
|
||||
32
pkg/protocol/rules/writers/SendErrorRule.go
Normal file
32
pkg/protocol/rules/writers/SendErrorRule.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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) (string, bool) {
|
||||
return rule.matcher.Build(SendErrorRulePrefix, argsData...)
|
||||
}
|
||||
32
pkg/protocol/rules/writers/SendOkRule.go
Normal file
32
pkg/protocol/rules/writers/SendOkRule.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package writers
|
||||
|
||||
import "StoreBackEnd/pkg/protocol"
|
||||
|
||||
// SendOkRulePrefix Rule command prefix
|
||||
const SendOkRulePrefix = "SEND_OK"
|
||||
|
||||
// SendOkRule Storage structure for the SendOkRule
|
||||
type SendOkRule struct {
|
||||
// cmd Rule name
|
||||
cmd string
|
||||
// matcher Allow to make a regex match
|
||||
matcher *protocol.RegexMatcher
|
||||
}
|
||||
|
||||
// CreateSendOkRule Creating an instance of SendOkRule
|
||||
func CreateSendOkRule(pattern string) protocol.IProtocolWriter {
|
||||
return &SendOkRule{
|
||||
cmd: SendOkRulePrefix,
|
||||
matcher: protocol.CreateRegexMatcher(pattern),
|
||||
}
|
||||
}
|
||||
|
||||
// GetCmd retrieve the command name.
|
||||
func (rule SendOkRule) GetCmd() string {
|
||||
return rule.cmd
|
||||
}
|
||||
|
||||
// Execute the Rule with a string command.
|
||||
func (rule SendOkRule) Execute(argsData ...string) (string, bool) {
|
||||
return rule.matcher.Build(SendOkRulePrefix, argsData...)
|
||||
}
|
||||
Reference in New Issue
Block a user