summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-03-25 20:26:30 +0100
committerxengineering <me@xengineering.eu>2024-03-25 20:27:16 +0100
commit9f1fc3ca35845a0fe5501f8a56646d6568e89e48 (patch)
treec38ade129c2237f5927db2bf06e3ed619a7a277d /config.go
parent7dd778cda189ea7debc7770a030fc831b9eab18b (diff)
downloadwebiot-9f1fc3ca35845a0fe5501f8a56646d6568e89e48.tar
webiot-9f1fc3ca35845a0fe5501f8a56646d6568e89e48.tar.zst
webiot-9f1fc3ca35845a0fe5501f8a56646d6568e89e48.zip
Make the parsed configuration a global variable
This removes the need to pass the configuration struct to every function.
Diffstat (limited to 'config.go')
-rw-r--r--config.go7
1 files changed, 3 insertions, 4 deletions
diff --git a/config.go b/config.go
index 3bb153b..f63d284 100644
--- a/config.go
+++ b/config.go
@@ -7,6 +7,8 @@ import (
"log"
)
+var config RuntimeConfig
+
type RuntimeConfig struct {
Devices DevicesConfig
Web WebConfig
@@ -22,7 +24,7 @@ type WebConfig struct {
// parseConfig() parses and validates the runtime configuration file and
// returns it as Go datastructure.
-func parseConfig(path string) RuntimeConfig {
+func parseConfig(path string) {
data, err := os.ReadFile(path)
if err != nil {
log.Fatalf("Could not read '%s'!", path)
@@ -32,11 +34,8 @@ func parseConfig(path string) RuntimeConfig {
log.Fatalf("%s contains invalid JSON!", path)
}
- config := RuntimeConfig{}
err = json.Unmarshal(data, &config)
if err != nil {
log.Fatalf("Could not parse configuration file:\n%s\n", err)
}
-
- return config
}