Chargement du fichier de config fonctionnelle. Reste à utiliser ses données
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user