StoreBackEnd/cmd/main.go

50 lines
1.4 KiB
Go
Raw Normal View History

package main
import (
"_StorBackEnd/pkg/config"
"_StorBackEnd/pkg/network"
"_StorBackEnd/pkg/protocol/managers"
2022-02-22 08:29:11 +01:00
"_StorBackEnd/pkg/protocol/repository"
2022-02-22 10:03:52 +01:00
"_StorBackEnd/pkg/protocol/rules/readers"
"_StorBackEnd/pkg/protocol/rules/writers"
)
const (
FILE_PATH = "resources/AppConfig.json"
MULTICAST_ADDRESS = "226.66.66.1:42500"
MULTICAST_SECOND = 10 // TODO : Changer en 30 secondes
UNICAST_ADDRESS = "0.0.0.0:58000"
)
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)
2022-02-22 08:29:11 +01:00
protocolRepository := repository.CreateProtocolRepository()
2022-02-22 10:03:52 +01:00
// Création des Writers
helloRule := writers.CreateHelloRule("^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$")
protocolRepository.AddWriter(&helloRule)
2022-02-22 10:03:52 +01:00
// Création des Readers
eraseFileRule := readers.CreateEraseFileRule("^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$")
2022-02-22 10:03:52 +01:00
protocolRepository.AddReader(&eraseFileRule)
2022-02-22 08:29:11 +01:00
multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND, protocolRepository)
go multicast.Run()
requestManager := managers.RequestManager{Repository: protocolRepository}
2022-02-22 08:29:11 +01:00
server := network.ServerUnicast{Network: "tcp", Address: UNICAST_ADDRESS, ReqManager: &requestManager}
server.Run()
}