Replace project constant by dynamic AppConfig.

This commit is contained in:
Benjamin Lejeune 2022-02-23 14:08:41 +01:00
parent 0808ed493d
commit dfd6096898

View File

@ -7,13 +7,11 @@ import (
"StorBackEnd/pkg/protocol/repository" "StorBackEnd/pkg/protocol/repository"
"StorBackEnd/pkg/protocol/rules/readers" "StorBackEnd/pkg/protocol/rules/readers"
"StorBackEnd/pkg/protocol/rules/writers" "StorBackEnd/pkg/protocol/rules/writers"
"time"
) )
const ( const (
FILE_PATH = "resources/AppConfig.json" 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() { func main() {
@ -38,12 +36,12 @@ func main() {
eraseFileRule := readers.CreateEraseFileRule("^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$") eraseFileRule := readers.CreateEraseFileRule("^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$")
protocolRepository.AddReader(&eraseFileRule) protocolRepository.AddReader(&eraseFileRule)
multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND, protocolRepository) multicast := network.CreateClientMulticast(appConfig.MulticastAddress, time.Duration(appConfig.MulticastSecond), protocolRepository)
go multicast.Run() go multicast.Run()
requestManager := managers.RequestManager{Repository: protocolRepository} requestManager := managers.RequestManager{Repository: protocolRepository}
server := network.ServerUnicast{Network: "tcp", Address: UNICAST_ADDRESS, ReqManager: &requestManager} server := network.ServerUnicast{Network: "tcp", Address: appConfig.UnicastAddress, ReqManager: &requestManager}
server.Run() server.Run()
} }