diff --git a/cmd/main.go b/cmd/main.go index f0f6af9..efb262e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,6 +1,8 @@ package main -import "_StorBackEnd/pkg/network" +import ( + "_StorBackEnd/pkg/network" +) const ( MULTICAST_ADDRESS = "226.0.0.1:42500" diff --git a/pkg/protocol/RegexMatcher.go b/pkg/protocol/RegexMatcher.go index e6a5d63..0e2774c 100644 --- a/pkg/protocol/RegexMatcher.go +++ b/pkg/protocol/RegexMatcher.go @@ -17,7 +17,7 @@ type RegexMatcher struct { matcher *regexp.Regexp } -// match Permet de vérifier la validité d'une donnée affiliée à un protocole -func (m RegexMatcher) match(data string) bool { +// Match Permet de vérifier la validité d'une donnée affiliée à un protocole +func (m RegexMatcher) Match(data string) bool { return m.matcher.MatchString(data) } diff --git a/pkg/protocol/rules/EraseFileRule.go b/pkg/protocol/rules/EraseFileRule.go new file mode 100644 index 0000000..253c827 --- /dev/null +++ b/pkg/protocol/rules/EraseFileRule.go @@ -0,0 +1,31 @@ +package rules + +import "_StorBackEnd/pkg/protocol" + +// EraseFileRule Demande de suppression d'un fichier +type EraseFileRule struct { + protocol.IProtocol + // Cmd Nom de la règle + Cmd string + + // matcher Permet de vérifier le matching + matcher *protocol.RegexMatcher +} + +// CreateEraseFileRule Création d'une instance de EraseFileRule +func CreateEraseFileRule(cmd string, pattern string) *EraseFileRule { + return &EraseFileRule{ + Cmd: cmd, + matcher: protocol.CreateRegexMatcher(pattern), + } +} + +func (rule EraseFileRule) execute(data string) { + matcher := rule.matcher + + if matcher.Match(data) { + println("EraseFileRule data is matching") + } else { + println("EraseFileRule data isn't matching") + } +} diff --git a/pkg/protocol/rules/HelloRule.go b/pkg/protocol/rules/HelloRule.go deleted file mode 100644 index 9da5f75..0000000 --- a/pkg/protocol/rules/HelloRule.go +++ /dev/null @@ -1,21 +0,0 @@ -package rules - -import "_StorBackEnd/pkg/protocol" - -type HelloRule struct { - cmd string - matcher *protocol.RegexMatcher -} - -func Create(cmd string, pattern string) *HelloRule { - h := new(HelloRule) - h.cmd = cmd - h.matcher = protocol.CreateRegexMatcher(pattern) - - return h -} - -func (rule HelloRule) execute(data string) { - //TODO implement me - panic("implement me") -}