add healthcheck service
This commit is contained in:
40
internal/store/memory/store.go
Normal file
40
internal/store/memory/store.go
Normal file
@ -0,0 +1,40 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"git.loyso.art/frx/devsim/internal/entities"
|
||||
)
|
||||
|
||||
type store struct {
|
||||
stats map[entities.DeviceID]entities.DeviceStatistics
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewStore() *store {
|
||||
return &store{
|
||||
stats: make(map[entities.DeviceID]entities.DeviceStatistics),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *store) List(ctx context.Context) ([]entities.DeviceStatistics, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
out := make([]entities.DeviceStatistics, 0, len(s.stats))
|
||||
for _, s := range s.stats {
|
||||
out = append(out, s)
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s *store) Upsert(ctx context.Context, stats entities.DeviceStatistics) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
s.stats[stats.ID] = stats
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user