Backend: Fixed some issues (files reading, config creation...)

This commit is contained in:
Yohan Boujon 2025-05-05 09:57:11 +02:00
parent 9e3a211cba
commit 84d43e1bb0
4 changed files with 14 additions and 9 deletions

View file

@ -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
}
}

View file

@ -1,3 +1,3 @@
module backend
go 1.24.2
go 1.23.6

View file

@ -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)

View file

@ -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
}