carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package assetcache
2
3import (
4 "crypto/sha256"
5 "encoding/binary"
6 "encoding/hex"
7)
8
9// Key identifies one cached response: which app generation served it, on
10// which host, for which path and query.
11type Key struct {
12 Account, App, Gen, Host, Path, RawQuery string
13}
14
15// ID is the hex sha256 over the six fields. Each field is written with its
16// length first, so no two distinct keys hash the same input.
17func (k Key) ID() string {
18 h := sha256.New()
19 var n [8]byte
20 for _, f := range [...]string{k.Account, k.App, k.Gen, k.Host, k.Path, k.RawQuery} {
21 binary.BigEndian.PutUint64(n[:], uint64(len(f)))
22 h.Write(n[:])
23 h.Write([]byte(f))
24 }
25 return hex.EncodeToString(h.Sum(nil))
26}
27
28// AppScope names the app this key belongs to, for per-app accounting.
29func (k Key) AppScope() string {
30 return k.Account + "/" + k.App
31}
32