blob: 92c53395ec302056e83b146f93dbaaef692fd642 [file] [log] [blame]
David K. Bainbridgef0da8732016-06-01 16:15:37 -07001package main
2
David K. Bainbridgef0da8732016-06-01 16:15:37 -07003type Storage interface {
4 Put(id string, update StatusMsg) error
5 Get(id string) (*StatusMsg, error)
6 List() ([]StatusMsg, error)
7}
8
9type MemoryStorage struct {
10 Data map[string]StatusMsg
11}
12
13func NewMemoryStorage() *MemoryStorage {
14 return &MemoryStorage{
15 Data: make(map[string]StatusMsg),
16 }
17}
18
19func (s *MemoryStorage) Put(id string, update StatusMsg) error {
20 s.Data[id] = update
David K. Bainbridgef0da8732016-06-01 16:15:37 -070021 return nil
22}
23
24func (s *MemoryStorage) Get(id string) (*StatusMsg, error) {
25 m, ok := s.Data[id]
26 if !ok {
27 return nil, nil
28 }
29 return &m, nil
30}
31
32func (s *MemoryStorage) List() ([]StatusMsg, error) {
33 r := make([]StatusMsg, len(s.Data))
34 i := 0
35 for _, v := range s.Data {
36 r[i] = v
David K. Bainbridge97ee8052016-06-14 00:52:07 -070037 i += 1
David K. Bainbridgef0da8732016-06-01 16:15:37 -070038 }
39 return r, nil
40}