Move log outside of func

This commit is contained in:
Svilen Markov 2024-11-30 10:59:58 +00:00
parent 02cbb5f812
commit b3e73ce86a

View file

@ -20,9 +20,17 @@ var _templateFS embed.FS
var staticFS, _ = fs.Sub(_staticFS, "static")
var templateFS, _ = fs.Sub(_templateFS, "templates")
var staticFSHash = computeFSHash(staticFS)
var staticFSHash = func() string {
hash, err := computeFSHash(staticFS)
if err != nil {
log.Printf("Could not compute static assets cache key: %v", err)
return strconv.FormatInt(time.Now().Unix(), 10)
}
func computeFSHash(files fs.FS) string {
return hash
}()
func computeFSHash(files fs.FS) (string, error) {
hash := md5.New()
err := fs.WalkDir(files, ".", func(path string, d fs.DirEntry, err error) error {
@ -46,10 +54,9 @@ func computeFSHash(files fs.FS) string {
return nil
})
if err == nil {
return hex.EncodeToString(hash.Sum(nil))[:10]
if err != nil {
return "", err
}
log.Printf("Could not compute assets cache: %v", err)
return strconv.FormatInt(time.Now().Unix(), 10)
return hex.EncodeToString(hash.Sum(nil))[:10], nil
}