package imagerequest import ( "crypto/sha256" "encoding/hex" "fmt" ) // SourceKey is a SHA256 hash identifying a cached source image (hex-encoded). type SourceKey string // Key returns the key the source is cached under, made as CacheKey makes a // variant key. // Format: sha256(host:path:query) // The path and query go through escapePercentAndColon, so that a ":" in // either cannot be taken for the one between them. func (s Source) Key() SourceKey { data := fmt.Sprintf("%s:%s:%s", s.Host, escapePercentAndColon(s.Path), escapePercentAndColon(s.Query), ) h := sha256.Sum256([]byte(data)) return SourceKey(hex.EncodeToString(h[:])) }