Backend: Fixed error checking and added time check.

This commit is contained in:
Yohan Boujon 2025-05-04 19:01:29 +02:00
parent 9c19c8afae
commit 9e3a211cba
2 changed files with 12 additions and 8 deletions

View file

@ -63,12 +63,14 @@ func getFileInfo(info fs.FileInfo, picd []PictureData, actualdir string) []Pictu
func ListFiles(path string) []PictureData { func ListFiles(path string) []PictureData {
var picd []PictureData var picd []PictureData
picd = listFiles(path, "", picd) picd = listFiles(path, "", picd)
println("") start := time.Now()
print("\n")
if len(picd) == 0 { if len(picd) == 0 {
util.Logformat(util.ERROR, "Could not gather any file.\n") util.Logformat(util.ERROR, "Could not gather any file.\n")
return nil return nil
} else { } else {
util.Logformat(util.CORRECT, "Gathered %d files.\n", len(picd)) elapsed := time.Since(start)
util.Logformat(util.CORRECT, "Gathered %d files in %dms.\n", len(picd), elapsed.Milliseconds())
return picd return picd
} }
} }

View file

@ -4,18 +4,23 @@ import (
"backend/core" "backend/core"
"backend/server" "backend/server"
"backend/util" "backend/util"
"strings" "errors"
"os"
) )
func main() { func main() {
// Set Log Level
util.SetLevel(util.NOLOG)
cfg, err := util.ReadConfig("config.json") cfg, err := util.ReadConfig("config.json")
if err != nil { if err != nil {
if strings.Compare(err.Error(), "open config.json: no such file or directory") == 0 { if errors.Is(err, os.ErrNotExist) {
util.Logformat(util.INFO, "Creating config file...\n") util.Logformat(util.INFO, "Creating config file...\n")
util.CreateConfig() util.CreateConfig()
cfg, err = util.ReadConfig("config.json") cfg, _ = util.ReadConfig("config.json")
} else { } else {
util.Logformat(util.ERROR, "Could not read configuration file: %s\n", err.Error()) util.Logformat(util.ERROR, "Could not read configuration file: %s\n", err.Error())
panic(err)
} }
} }
@ -23,9 +28,6 @@ func main() {
util.Logformat(util.INFO, "Reading folder '%s'\n", cfg.PhotoPath) util.Logformat(util.INFO, "Reading folder '%s'\n", cfg.PhotoPath)
core.ListFiles(cfg.PhotoPath) core.ListFiles(cfg.PhotoPath)
// Set Log Level
util.SetLevel(util.NOLOG)
// Rest API start on port // Rest API start on port
server.Start(8085) server.Start(8085)
} }