Files
Sotig 0c40983293 ui
2026-05-29 21:16:10 +03:00

35 lines
824 B
Go

package cache
import (
"crypto/sha256"
"fmt"
"io"
"os"
)
// HashFile computes the SHA-256 hex digest of the file at path.
func HashFile(path string) (string, error) {
f, err := os.Open(path)
if err != nil {
return "", err
}
defer f.Close()
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
return "", err
}
return fmt.Sprintf("%x", h.Sum(nil)), nil
}
// AnalysisKey builds a cache key for FFF or SLA analysis.
// Format: "<endpoint>:<filehash>:scale=<scale>"
// scale uses %.6g so "1.50" and "1.5" map to the same key.
func AnalysisKey(endpoint, fileHash string, scale float64) string {
return fmt.Sprintf("%s:%s:scale=%.6g", endpoint, fileHash, scale)
}
// ThumbnailKey builds a cache key for thumbnail generation.
func ThumbnailKey(fileHash string) string {
return "thumbnail:" + fileHash
}