diff --git a/backend/core/file.go b/backend/core/file.go index e60998c..051eb58 100644 --- a/backend/core/file.go +++ b/backend/core/file.go @@ -2,6 +2,7 @@ package core import ( "backend/util" + "errors" "io/fs" "os" "strings" @@ -60,17 +61,16 @@ func getFileInfo(info fs.FileInfo, picd []PictureData, actualdir string) []Pictu return picd } -func ListFiles(path string) []PictureData { +func ListFiles(path string) ([]PictureData, error) { var picd []PictureData - picd = listFiles(path, "", picd) start := time.Now() - print("\n") + picd = listFiles(path, "", picd) if len(picd) == 0 { - util.Logformat(util.ERROR, "Could not gather any file.\n") - return nil + return nil, errors.New("ListFiles(): Could not gather any file") } else { elapsed := time.Since(start) + print("\n") util.Logformat(util.CORRECT, "Gathered %d files in %dms.\n", len(picd), elapsed.Milliseconds()) - return picd + return picd, nil } } diff --git a/backend/go.mod b/backend/go.mod index 9be7739..4164d1a 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -1,3 +1,3 @@ module backend -go 1.24.2 +go 1.23.6 diff --git a/backend/main.go b/backend/main.go index 690bdcd..0d9947c 100644 --- a/backend/main.go +++ b/backend/main.go @@ -20,13 +20,17 @@ func main() { cfg, _ = util.ReadConfig("config.json") } else { util.Logformat(util.ERROR, "Could not read configuration file: %s\n", err.Error()) - panic(err) + os.Exit(2) } } // Reading files util.Logformat(util.INFO, "Reading folder '%s'\n", cfg.PhotoPath) - core.ListFiles(cfg.PhotoPath) + _, err = core.ListFiles(cfg.PhotoPath) + if err != nil { + util.Logformat(util.ERROR, "%s\n", err.Error()) + os.Exit(3) + } // Rest API start on port server.Start(8085) diff --git a/backend/util/config.go b/backend/util/config.go index 7405c3b..1e50275 100644 --- a/backend/util/config.go +++ b/backend/util/config.go @@ -19,6 +19,7 @@ func ReadConfig(path string) (Config, error) { defer file.Close() decoder := json.NewDecoder(file) + decoder.DisallowUnknownFields() err = decoder.Decode(&cfg) return cfg, err }