go project - add a migration and rename the dockerfiles so that Go is the primary
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package store
|
||||
|
||||
import "sync"
|
||||
|
||||
// DeviceID is a typed device identifier.
|
||||
// Using a named type (instead of plain string) makes call sites clearer
|
||||
// and prevents accidentally mixing unrelated string values.
|
||||
type DeviceID string
|
||||
|
||||
// Store holds in-memory fleet metrics for known devices.
|
||||
type Store struct {
|
||||
known map[DeviceID]struct{}
|
||||
|
||||
// mu protects the heartbeats/uploads maps (insert/lookup of entries only).
|
||||
// Each per-device history has its own mutex for mutations.
|
||||
mu sync.Mutex
|
||||
heartbeats map[DeviceID]*heartbeatHistory
|
||||
uploads map[DeviceID]*uploadHistory
|
||||
}
|
||||
|
||||
// New creates a Store seeded with the given known device IDs.
|
||||
func New(known []DeviceID) *Store {
|
||||
m := make(map[DeviceID]struct{}, len(known))
|
||||
for _, id := range known {
|
||||
m[id] = struct{}{}
|
||||
}
|
||||
return &Store{
|
||||
known: m,
|
||||
heartbeats: make(map[DeviceID]*heartbeatHistory),
|
||||
uploads: make(map[DeviceID]*uploadHistory),
|
||||
}
|
||||
}
|
||||
|
||||
// Known reports whether deviceID was present in the startup device list.
|
||||
func (s *Store) Known(deviceID DeviceID) bool {
|
||||
_, ok := s.known[deviceID]
|
||||
return ok
|
||||
}
|
||||
Reference in New Issue
Block a user