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 (
|
import (
|
||||||
"backend/util"
|
"backend/util"
|
||||||
|
"errors"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -60,17 +61,16 @@ func getFileInfo(info fs.FileInfo, picd []PictureData, actualdir string) []Pictu
|
||||||
return picd
|
return picd
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListFiles(path string) []PictureData {
|
func ListFiles(path string) ([]PictureData, error) {
|
||||||
var picd []PictureData
|
var picd []PictureData
|
||||||
picd = listFiles(path, "", picd)
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
print("\n")
|
picd = listFiles(path, "", picd)
|
||||||
if len(picd) == 0 {
|
if len(picd) == 0 {
|
||||||
util.Logformat(util.ERROR, "Could not gather any file.\n")
|
return nil, errors.New("ListFiles(): Could not gather any file")
|
||||||
return nil
|
|
||||||
} else {
|
} else {
|
||||||
elapsed := time.Since(start)
|
elapsed := time.Since(start)
|
||||||
|
print("\n")
|
||||||
util.Logformat(util.CORRECT, "Gathered %d files in %dms.\n", len(picd), elapsed.Milliseconds())
|
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
|
module backend
|
||||||
|
|
||||||
go 1.24.2
|
go 1.23.6
|
||||||
|
|
|
@ -20,13 +20,17 @@ func main() {
|
||||||
cfg, _ = 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)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reading files
|
// Reading files
|
||||||
util.Logformat(util.INFO, "Reading folder '%s'\n", cfg.PhotoPath)
|
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
|
// Rest API start on port
|
||||||
server.Start(8085)
|
server.Start(8085)
|
||||||
|
|
|
@ -19,6 +19,7 @@ func ReadConfig(path string) (Config, error) {
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
decoder := json.NewDecoder(file)
|
decoder := json.NewDecoder(file)
|
||||||
|
decoder.DisallowUnknownFields()
|
||||||
err = decoder.Decode(&cfg)
|
err = decoder.Decode(&cfg)
|
||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue