/
reloading_store.go
68 lines (60 loc) · 1.81 KB
/
reloading_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package rule
import (
"github.com/chrisruffalo/gudgeon/config"
"github.com/chrisruffalo/gudgeon/events"
"sync"
)
type reloadingStore struct {
handlers []*events.Handle
delegate Store
mux sync.RWMutex
}
func (reloadingStore *reloadingStore) Init(sessionRoot string, config *config.GudgeonConfig, lists []*config.GudgeonList) {
if reloadingStore.delegate != nil {
reloadingStore.mux.Lock()
reloadingStore.delegate.Init(sessionRoot, config, lists)
reloadingStore.mux.Unlock()
}
}
func (reloadingStore *reloadingStore) Clear(config *config.GudgeonConfig, list *config.GudgeonList) {
if reloadingStore.delegate != nil {
reloadingStore.mux.Lock()
reloadingStore.delegate.Clear(config, list)
reloadingStore.mux.Unlock()
}
}
func (reloadingStore *reloadingStore) Load(list *config.GudgeonList, rule string) {
if reloadingStore.delegate != nil {
reloadingStore.mux.Lock()
reloadingStore.delegate.Load(list, rule)
reloadingStore.mux.Unlock()
}
}
func (reloadingStore *reloadingStore) Finalize(sessionRoot string, lists []*config.GudgeonList) {
if reloadingStore.delegate != nil {
reloadingStore.mux.Lock()
reloadingStore.delegate.Finalize(sessionRoot, lists)
reloadingStore.mux.Unlock()
}
}
func (reloadingStore *reloadingStore) FindMatch(lists []*config.GudgeonList, domain string) (Match, *config.GudgeonList, string) {
if reloadingStore.delegate != nil {
reloadingStore.mux.RLock()
defer reloadingStore.mux.RUnlock()
return reloadingStore.delegate.FindMatch(lists, domain)
}
return MatchNone, nil, ""
}
func (reloadingStore *reloadingStore) Close() {
if reloadingStore.delegate != nil {
reloadingStore.mux.Lock()
// close handles
for _, handle := range reloadingStore.handlers {
if handle != nil {
handle.Close()
}
}
reloadingStore.delegate.Close()
reloadingStore.mux.Unlock()
}
}