mirror of
https://github.com/git-pkgs/proxy.git
synced 2026-11-09 15:49:16 -05:00
21 lines
571 B
Go
21 lines
571 B
Go
package handler
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"strconv"
|
|
)
|
|
|
|
// hashedCacheKey derives a metadata cache key from parts such as the
|
|
// upstream URL, the request path and the query. Each part is length-prefixed
|
|
// before hashing, so no two different part lists share a key, whatever bytes
|
|
// the parts contain.
|
|
func hashedCacheKey(parts ...string) string {
|
|
h := sha256.New()
|
|
for _, part := range parts {
|
|
_, _ = h.Write([]byte(strconv.Itoa(len(part))))
|
|
_, _ = h.Write([]byte{':'})
|
|
_, _ = h.Write([]byte(part))
|
|
}
|
|
return hex.EncodeToString(h.Sum(nil))
|
|
}
|