From 4c368ef551a66ded1c449090e2eab47fbfe0709b Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 19 Feb 2022 18:10:52 +0100 Subject: [PATCH] =?UTF-8?q?RegexMatcher.go=20:=20-=20Suppression=20HelloRu?= =?UTF-8?q?le.go=20qui=20n'=C3=A9tait=20pas=20adapt=C3=A9e=20-=20Cr=C3=A9a?= =?UTF-8?q?tion=20EraseFileRule.go=20et=20impl=C3=A9mentation=20de=20son?= =?UTF-8?q?=20interface=20IProtocol.go=20=20-=20Rename=20m=C3=A9thode=20Re?= =?UTF-8?q?gexMatcher.go=20match=20->=20Match?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 4 +++- pkg/protocol/RegexMatcher.go | 4 ++-- pkg/protocol/rules/EraseFileRule.go | 31 +++++++++++++++++++++++++++++ pkg/protocol/rules/HelloRule.go | 21 ------------------- 4 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 pkg/protocol/rules/EraseFileRule.go delete mode 100644 pkg/protocol/rules/HelloRule.go 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") -}