Chargement du fichier de config fonctionnelle. Reste à utiliser ses données
This commit is contained in:
parent
6553ebead0
commit
f6a7004137
11
cmd/main.go
11
cmd/main.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"_StorBackEnd/pkg/config"
|
||||
"_StorBackEnd/pkg/network"
|
||||
"_StorBackEnd/pkg/protocol/managers"
|
||||
"_StorBackEnd/pkg/protocol/repository"
|
||||
@ -9,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
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"
|
||||
@ -17,6 +19,15 @@ const (
|
||||
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
|
||||
|
@ -3,26 +3,11 @@ package config
|
||||
// AppConfig Contient toute la configuration du server
|
||||
type AppConfig struct {
|
||||
// multicastAddress Contient l'adresse multicast du FileFrontEnd (adresse:port)
|
||||
multicastAddress string `json:"multicastAddress"`
|
||||
MulticastAddress string `json:"multicastAddress"`
|
||||
|
||||
// multicastSecond Contient le nombre de seconde entre chaque annonce
|
||||
multicastSecond int `json:"multicastSecond"`
|
||||
MulticastSecond int `json:"multicastSecond"`
|
||||
|
||||
// unicastAddress Contient l'adresse unicast auquel le FileFrontEnd se connecte (adresse:port)
|
||||
unicastAddress string `json:"unicastAddress"`
|
||||
}
|
||||
|
||||
// MulticastAddress Accesseur pour multicastAddress
|
||||
func (a *AppConfig) MulticastAddress() string {
|
||||
return a.multicastAddress
|
||||
}
|
||||
|
||||
// MulticastSecond Accesseur pour multicastSecond
|
||||
func (a *AppConfig) MulticastSecond() int {
|
||||
return a.multicastSecond
|
||||
}
|
||||
|
||||
// UnicastAddress Accesseur pour unicastAddress
|
||||
func (a *AppConfig) UnicastAddress() string {
|
||||
return a.unicastAddress
|
||||
UnicastAddress string `json:"unicastAddress"`
|
||||
}
|
||||
|
21
pkg/config/JsonConfigReader.go
Normal file
21
pkg/config/JsonConfigReader.go
Normal file
@ -0,0 +1,21 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func Read(filePath string) (*AppConfig, error) {
|
||||
config := AppConfig{}
|
||||
file, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
errJson := json.Unmarshal(file, &config)
|
||||
if errJson != nil {
|
||||
return nil, errJson
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user