-
Notifications
You must be signed in to change notification settings - Fork 193
/
health.go
75 lines (62 loc) · 1.51 KB
/
health.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
69
70
71
72
73
74
75
package health
import (
"fmt"
"github.com/abh/geodns/v3/typeutil"
)
type HealthTester interface {
// Test(record string) bool
Name(record string) string
String() string
}
type HealthReference struct {
name string
}
func (hr *HealthReference) Name(record string) string {
if len(record) > 0 {
return hr.name + "/" + record
}
return hr.name
}
func (hr *HealthReference) String() string {
return hr.name
}
func NewReferenceFromMap(i map[string]interface{}) (HealthTester, error) {
var name, ts string
if ti, ok := i["type"]; ok {
ts = typeutil.ToString(ti)
}
if ni, ok := i["name"]; ok {
name = typeutil.ToString(ni)
}
if len(name) == 0 {
name = ts
}
if len(name) == 0 {
return nil, fmt.Errorf("name or type required")
}
tester := &HealthReference{name: name}
return tester, nil
}
// func (hr *HealthReference) RecordTest(rec *zones.Record) {
// key := ht.String()
// htr.entryMutex.Lock()
// defer htr.entryMutex.Unlock()
// if t, ok := htr.entries[key]; ok {
// // we already have an instance of this test running. Record we are using it
// t.references[ref] = true
// } else {
// // a test that isn't running. Record we are using it and start the test
// t := &HealthTestRunnerEntry{
// HealthTest: *ht.copy(ht.ipAddress),
// references: make(map[string]bool),
// }
// if t.global {
// t.ipAddress = nil
// }
// // we know it is not started, so no need for the mutex
// t.healthy = ht.healthy
// t.references[ref] = true
// t.start()
// htr.entries[key] = t
// }
// }