-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
52 lines (45 loc) · 1.05 KB
/
store.go
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
43
44
45
46
47
48
49
50
51
52
package main
import (
"sync"
)
// Store is a simple key/value map
type Store struct {
mx sync.Mutex
m map[string]map[string]BadgeData
}
// GetLast BadgeData for provided Project and Subject
func (s *Store) GetLast(project Project, subject Subject) (BadgeData, bool) {
s.mx.Lock()
defer s.mx.Unlock()
v, ok := s.m[project.toString()]
if ok {
v, ok := v[subject.toString()]
return v, ok
}
return BadgeData{}, ok
}
// Store BadgeData to provided Project and Subject
func (s *Store) Store(project Project, subject Subject, badge BadgeData) *Store {
s.mx.Lock()
defer s.mx.Unlock()
v, ok := s.m[project.toString()]
if !ok {
v = make(map[string]BadgeData)
s.m[project.toString()] = v
}
v[subject.toString()] = badge
return s
}
// GetProjectBadges return badges for project
func (s *Store) GetProjectBadges(project Project) (map[string]BadgeData, bool) {
s.mx.Lock()
defer s.mx.Unlock()
v, ok := s.m[project.toString()]
return v, ok
}
// NewStore creates store
func NewStore() *Store {
return &Store{
m: make(map[string]map[string]BadgeData),
}
}