-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_registry.go
43 lines (38 loc) · 949 Bytes
/
check_registry.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
package bun
import (
"fmt"
"sync"
)
var (
checkRegistry = make(map[string]Check)
checkRegistryMu sync.RWMutex
)
// RegisterCheck registers a new check to make it discoverable for consumers.
func RegisterCheck(c Check) {
checkRegistryMu.Lock()
defer checkRegistryMu.Unlock()
if _, exists := checkRegistry[c.Name]; exists {
panic(fmt.Sprintf("bun.RegisterCheck: called twice for check %v", c.Name))
}
checkRegistry[c.Name] = c
}
// Checks Returns all registered checks.
func Checks() []Check {
checkRegistryMu.RLock()
defer checkRegistryMu.RUnlock()
checks := make([]Check, 0, len(checkRegistry))
for _, c := range checkRegistry {
checks = append(checks, c)
}
return checks
}
// GetCheck returns check by name.
func GetCheck(name string) Check {
checkRegistryMu.RLock()
check, ok := checkRegistry[name]
checkRegistryMu.RUnlock()
if !ok {
panic(fmt.Sprintf("bun.GetCheck: don't have check %v", name))
}
return check
}