2023-08-09 09:08:05 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2023-08-10 14:09:17 -05:00
|
|
|
"io"
|
2023-08-09 09:08:05 -05:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AbstractConfig struct {
|
|
|
|
MulticastConfig struct {
|
2023-08-10 14:09:17 -05:00
|
|
|
MIPAddr string `json:"MIpAddr"`
|
|
|
|
MPort string `json:"MPort"`
|
|
|
|
MaxDatagramSize int `json:"MaxDatagramSize"`
|
2023-08-09 09:08:05 -05:00
|
|
|
} `json:"MulticastConfig"`
|
|
|
|
InterfaceConfig struct {
|
|
|
|
ExistingInterface string `json:"ExistingInterface"`
|
|
|
|
BridgeIPCIDR string `json:"BridgeIpCIDR"`
|
|
|
|
} `json:"InterfaceConfig"`
|
2023-08-10 14:09:17 -05:00
|
|
|
Debug bool `json:"debug"`
|
2023-08-09 09:08:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var a AbstractConfig
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
//reading json file
|
|
|
|
file, err := os.ReadFile("zoreide.json")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Cannot open config file", err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(file), &a)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Cannot marshal json: ", err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
MulticastEntity.MIpAddr = a.MulticastConfig.MIPAddr
|
|
|
|
MulticastEntity.MPort = a.MulticastConfig.MPort
|
|
|
|
MulticastEntity.MaxDatagramSize = numberlenght
|
|
|
|
|
|
|
|
ZoreideBridge.BridgeIpCIDR = a.InterfaceConfig.BridgeIPCIDR
|
|
|
|
ZoreideBridge.ExistingInterface = a.InterfaceConfig.ExistingInterface
|
|
|
|
ZoreideBridge.IsActive = false
|
|
|
|
|
2023-08-10 14:09:17 -05:00
|
|
|
if !a.Debug {
|
|
|
|
log.SetOutput(io.Discard)
|
|
|
|
}
|
|
|
|
|
2023-08-09 09:08:05 -05:00
|
|
|
log.Println("Inizialized Generic Config: ", a)
|
|
|
|
log.Println("Inizialized Interface Config: ", ZoreideBridge)
|
|
|
|
log.Println("Inizialized Multicast Config: ", MulticastEntity)
|
|
|
|
|
|
|
|
}
|