From 9fb7771281f0ece0669e52adc07d91dbca227bdb Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Thu, 1 Sep 2022 12:41:48 +0200 Subject: [PATCH] json error handling --- main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 0b49d6c..6b58b8b 100644 --- a/main.go +++ b/main.go @@ -45,12 +45,11 @@ func parseFlags() { flag.Parse() } -func isError(err error) bool { +func handleError(err error) { if err != nil { fmt.Println(err.Error()) os.Exit(1) } - return (err != nil) } func readJson() { @@ -66,13 +65,14 @@ func readJson() { fmt.Println("Opening file:", path) var file, err = os.Open(path) - if isError(err) { - return - } + handleError(err) defer file.Close() byteValue, _ := ioutil.ReadAll(file) - json.Unmarshal(byteValue, &char) + + err = json.Unmarshal(byteValue, &char) + handleError(err) + } func initMaps() {