d77991c95a
* feat: port * fix: use httprouter * fix: WriteHeader * fix: bolthold * fix: bugs * chore: one less file * test: test handler * fix: bug in id * test: fix cases * chore: tidy * fix: use atomic.Int32 * fix: use atomic.Store * feat: support close * chore: lint * fix: cache keys are case insensitive * fix: options * fix: use options * fix: close * fix: ignore close error * Revert "fix: close" This reverts commit d53ea7568ba03908eb153031c435008fd47e7ccb. * fix: cacheUrlKey * fix: nil close * chore: lint code * fix: test key * test: case insensitive * chore: lint
38 lines
960 B
Go
38 lines
960 B
Go
package artifactcache
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"fmt"
|
|
)
|
|
|
|
type Request struct {
|
|
Key string `json:"key" `
|
|
Version string `json:"version"`
|
|
Size int64 `json:"cacheSize"`
|
|
}
|
|
|
|
func (c *Request) ToCache() *Cache {
|
|
if c == nil {
|
|
return nil
|
|
}
|
|
return &Cache{
|
|
Key: c.Key,
|
|
Version: c.Version,
|
|
Size: c.Size,
|
|
}
|
|
}
|
|
|
|
type Cache struct {
|
|
ID uint64 `json:"id" boltholdKey:"ID"`
|
|
Key string `json:"key" boltholdIndex:"Key"`
|
|
Version string `json:"version" boltholdIndex:"Version"`
|
|
KeyVersionHash string `json:"keyVersionHash" boltholdUnique:"KeyVersionHash"`
|
|
Size int64 `json:"cacheSize"`
|
|
Complete bool `json:"complete"`
|
|
UsedAt int64 `json:"usedAt" boltholdIndex:"UsedAt"`
|
|
CreatedAt int64 `json:"createdAt" boltholdIndex:"CreatedAt"`
|
|
}
|
|
|
|
func (c *Cache) FillKeyVersionHash() {
|
|
c.KeyVersionHash = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprintf("%s:%s", c.Key, c.Version))))
|
|
}
|