-
Notifications
You must be signed in to change notification settings - Fork 9
/
storage.go
53 lines (45 loc) · 870 Bytes
/
storage.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
53
package main
import (
"sync"
)
var (
storageIns Storage
storageOnce sync.Once
)
type Storage interface {
Refresh()
Get(secret string) []Authorization
Set(secret string, auth []Authorization)
}
type storage struct {
sync.RWMutex
data map[string][]Authorization
}
func (s *storage) Refresh() {
s.Lock()
defer s.Unlock()
s.data = make(map[string][]Authorization)
for _, v := range GetPlugins() {
for secret, auth := range v.Authorization() {
s.data[secret] = auth
}
}
}
func (s *storage) Get(secret string) []Authorization {
s.RLock()
defer s.RUnlock()
return s.data[secret]
}
func (s *storage) Set(secret string, auth []Authorization) {
s.Lock()
defer s.Unlock()
s.data[secret] = auth
}
func GetStorage() Storage {
storageOnce.Do(func() {
storageIns = &storage{
data: make(map[string][]Authorization),
}
})
return storageIns
}