From 2edf00073f7699e451ad4925348d21a58f8e73c1 Mon Sep 17 00:00:00 2001 From: Noah Date: Wed, 27 Mar 2024 10:21:56 -0500 Subject: [PATCH] Tell the user if given an invalid / non-existant config file (fix #29) --- config.go | 2 +- main.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 59800a1..b4ce5bb 100644 --- a/config.go +++ b/config.go @@ -25,7 +25,7 @@ func parseConfig(path string, config *Configuration) { var data map[string]interface{} err := json.NewDecoder(file).Decode(&data) if err != nil { - log.Panic("Failed to parse config:", err) + log.Panic("Failed to parse config: ", err) } file.Close() // Main configuration diff --git a/main.go b/main.go index 97ece38..2733ff9 100644 --- a/main.go +++ b/main.go @@ -82,6 +82,13 @@ func main() { return } + if exists, err := fileExists(*config_path); !exists { + fmt.Printf("Invalid config file '%s'\n", *config_path) + os.Exit(1) + } else if err != nil { + panic(err) + } + parseConfig(*config_path, &configuration) // Parse JSON configuration file http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // Webhook receiver