Clean up error handling, migrate to log/slog, add todo for flash message system in post controller

This commit is contained in:
Maximilian
2023-09-03 15:45:12 -05:00
parent ee4c9f9199
commit ed712a5344
10 changed files with 51 additions and 68 deletions

View File

@ -3,7 +3,7 @@ package config
import (
"encoding/json"
"flag"
"log"
"log/slog"
"os"
)
@ -33,13 +33,13 @@ func LoadConfig() Configuration {
flag.Parse()
file, err := os.Open(*c)
if err != nil {
log.Fatal("Unable to open JSON config file: ", err)
panic("Unable to open JSON config file: " + err.Error())
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
log.Fatal("Unable to close JSON config file: ", err)
slog.Error("Unable to close JSON config file: ", err)
}
}(file)
@ -47,7 +47,7 @@ func LoadConfig() Configuration {
Config := Configuration{}
err = decoder.Decode(&Config)
if err != nil {
log.Fatal("Unable to decode JSON config file: ", err)
panic("Unable to decode JSON config file: " + err.Error())
}
return Config