StoreBackEnd/cmd/main.go

48 lines
1.3 KiB
Go

package main
import (
"StorBackEnd/pkg/config"
"StorBackEnd/pkg/network"
"StorBackEnd/pkg/protocol/managers"
"StorBackEnd/pkg/protocol/repository"
"StorBackEnd/pkg/protocol/rules/readers"
"StorBackEnd/pkg/protocol/rules/writers"
"time"
)
const (
FILE_PATH = "resources/AppConfig.json"
)
func main() {
println("StorBackEnd started !")
// Loading App config
appConfig, err := config.Read(FILE_PATH)
if err != nil {
println("Impossible de charger la configuration du server : " + err.Error())
return
}
println("Adresse multicast : " + appConfig.MulticastAddress)
protocolRepository := repository.CreateProtocolRepository()
// Création des Writers
helloRule := writers.CreateHelloRule("^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$")
protocolRepository.AddWriter(&helloRule)
// Création des Readers
eraseFileRule := readers.CreateEraseFileRule("^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$")
protocolRepository.AddReader(&eraseFileRule)
multicast := network.CreateClientMulticast(appConfig.MulticastAddress, time.Duration(appConfig.MulticastSecond), protocolRepository)
go multicast.Run()
requestManager := managers.RequestManager{Repository: protocolRepository}
server := network.ServerUnicast{Network: "tcp", Address: appConfig.UnicastAddress, ReqManager: &requestManager}
server.Run()
}