-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
42 lines (35 loc) · 996 Bytes
/
types.go
File metadata and controls
42 lines (35 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import "sync"
type PackageStats struct {
Owner string
Package string
TotalPulls int
LatestVersion string
Architectures []string
PlatformSizes map[string]int64 // key: "linux/amd64" or "" for unknown platform; value: compressed bytes
ScrapedAt int64 // unix timestamp
}
type Cache struct {
mu sync.RWMutex
stats map[string]*PackageStats // key: "owner/package"
}
func NewCache() *Cache {
return &Cache{stats: make(map[string]*PackageStats)}
}
func (c *Cache) Get(key string) *PackageStats {
c.mu.RLock()
defer c.mu.RUnlock()
return c.stats[key]
}
func (c *Cache) Set(key string, s *PackageStats) {
c.mu.Lock()
defer c.mu.Unlock()
c.stats[key] = s
}
// BadgeResponse is the shields.io endpoint-badge schema: https://shields.io/badges/endpoint-badge
type BadgeResponse struct {
SchemaVersion int `json:"schemaVersion"`
Label string `json:"label"`
Message string `json:"message"`
Color string `json:"color"`
}