StoreBackEnd/cmd/main.go

72 lines
2.3 KiB
Go
Raw Normal View History

package main
import (
"StoreBackEnd/pkg/config"
"StoreBackEnd/pkg/network"
"StoreBackEnd/pkg/protocol/managers"
"StoreBackEnd/pkg/protocol/repository"
"StoreBackEnd/pkg/protocol/rules/readers"
"StoreBackEnd/pkg/protocol/rules/writers"
"time"
)
const (
FilePath = "resources/AppConfig.json"
)
func main() {
println("StoreBackEnd started !")
// Loading App config
appConfig, err := config.Read(FilePath)
if err != nil {
println("Impossible de charger la configuration du server : " + err.Error())
return
}
println("Multicast Address : " + appConfig.MulticastAddress)
println("StoreBacked Domain : " + appConfig.Domain)
2022-02-22 08:29:11 +01:00
protocolRepository := repository.CreateProtocolRepository()
2022-02-22 10:03:52 +01:00
/**
===== Init all Write here =====
*/
// Creation of the HelloRule
helloRule := writers.CreateHelloRule("^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$")
protocolRepository.AddWriter(&helloRule)
// Creation of the SendOkRule
sendOkRule := writers.CreateSendOkRule("^SEND_OK\n$")
protocolRepository.AddWriter(&sendOkRule)
// Creation of the SendErrorRule
sendErrorRule := writers.CreateSendOkRule("^SEND_ERROR\n$")
protocolRepository.AddWriter(&sendErrorRule)
/**
===== Init all Reader here =====
*/
// Creation of the EraseFileRule
eraseFileRule := readers.CreateEraseFileRule("^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$")
2022-02-22 10:03:52 +01:00
protocolRepository.AddReader(&eraseFileRule)
// Creation of the SendFileRule // TODO reset to 50,200
sendFileRule := readers.CreateSendFileRule("^SENDFILE ([A-Za-z0-9.]{1,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n$")
protocolRepository.AddReader(&sendFileRule)
// Create a Multicast Client & run it
2022-02-26 18:08:52 +01:00
multicast := network.CreateClientMulticast(appConfig.MulticastAddress, appConfig.Domain, appConfig.UnicastPort, time.Duration(appConfig.MulticastSecond), protocolRepository)
go multicast.Run()
requestManager := managers.RequestManager{Repository: protocolRepository}
2022-02-22 08:29:11 +01:00
2022-02-26 18:08:52 +01:00
server := network.ServerUnicast{Network: "tcp", Port: appConfig.UnicastPort, ReqManager: &requestManager}
server.Run() // TODO : -> pourquoi ne pas partir dans un thread ici.
//reader := bufio.NewReader(os.Stdin) TODO ne pas oublier ici de mettre en place un point de sortie pour le programme.
//fmt.Print("Type Enter to quite: ")
//cmd, _ := reader.ReadString('\n')
//println(cmd)
}