poc of functions
This commit is contained in:
34
internal/cache/key.go
vendored
Normal file
34
internal/cache/key.go
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user