Backend: Fixed error checking and added time check.
This commit is contained in:
parent
9c19c8afae
commit
9e3a211cba
2 changed files with 12 additions and 8 deletions
|
@ -63,12 +63,14 @@ func getFileInfo(info fs.FileInfo, picd []PictureData, actualdir string) []Pictu
|
|||
func ListFiles(path string) []PictureData {
|
||||
var picd []PictureData
|
||||
picd = listFiles(path, "", picd)
|
||||
println("")
|
||||
start := time.Now()
|
||||
print("\n")
|
||||
if len(picd) == 0 {
|
||||
util.Logformat(util.ERROR, "Could not gather any file.\n")
|
||||
return nil
|
||||
} 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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,18 +4,23 @@ import (
|
|||
"backend/core"
|
||||
"backend/server"
|
||||
"backend/util"
|
||||
"strings"
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Set Log Level
|
||||
util.SetLevel(util.NOLOG)
|
||||
|
||||
cfg, err := util.ReadConfig("config.json")
|
||||
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.CreateConfig()
|
||||
cfg, err = util.ReadConfig("config.json")
|
||||
cfg, _ = util.ReadConfig("config.json")
|
||||
} else {
|
||||
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)
|
||||
core.ListFiles(cfg.PhotoPath)
|
||||
|
||||
// Set Log Level
|
||||
util.SetLevel(util.NOLOG)
|
||||
|
||||
// Rest API start on port
|
||||
server.Start(8085)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue