diff options
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -7,6 +7,7 @@ import ( "log" "net" "net/url" + "os" "regexp" "strconv" "time" @@ -120,7 +121,21 @@ func (sc *StartupConfig) FromJSON(data []byte) error { return nil } -func GetStartupConfig() StartupConfig { +func (sc *StartupConfig) FromFile(path string) error { + data, err := os.ReadFile(path) + if err != nil { + return fmt.Errorf("Failed to read config file '%s': %w", path, err) + } + + err = sc.FromJSON(data) + if err != nil { + return fmt.Errorf("Could not parse config file '%s': %w", path, err) + } + + return nil +} + +func GetStartupConfig(path string) StartupConfig { config := StartupConfig{} err := config.FromJSON(defaultConfig) @@ -128,5 +143,14 @@ func GetStartupConfig() StartupConfig { log.Fatalf("Could not parse default config: %v", err) } + if path != "" { + log.Printf("Config path: %s", path) + + err = config.FromFile(path) + if err != nil { + log.Fatalf("Failed to read configuration: %v", err) + } + } + return config } |
