Backend: Fixed some issues (files reading, config creation...)
This commit is contained in:
parent
9e3a211cba
commit
84d43e1bb0
4 changed files with 14 additions and 9 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module backend
|
||||
|
||||
go 1.24.2
|
||||
go 1.23.6
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue