-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
option.go
93 lines (71 loc) · 1.54 KB
/
option.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package prom
import (
"sync"
"github.com/ccfos/nightingale/v6/pkg/tlsx"
)
type PromOption struct {
ClusterName string
Url string
WriteAddr string
BasicAuthUser string
BasicAuthPass string
Timeout int64
DialTimeout int64
MaxIdleConnsPerHost int
Headers []string
tlsx.ClientConfig
}
func (po *PromOption) Equal(target PromOption) bool {
if po.Url != target.Url {
return false
}
if po.BasicAuthUser != target.BasicAuthUser {
return false
}
if po.BasicAuthPass != target.BasicAuthPass {
return false
}
if po.WriteAddr != target.WriteAddr {
return false
}
if po.Timeout != target.Timeout {
return false
}
if po.DialTimeout != target.DialTimeout {
return false
}
if po.MaxIdleConnsPerHost != target.MaxIdleConnsPerHost {
return false
}
if len(po.Headers) != len(target.Headers) {
return false
}
for i := 0; i < len(po.Headers); i++ {
if po.Headers[i] != target.Headers[i] {
return false
}
}
return true
}
type PromOptionsStruct struct {
Data map[int64]PromOption
sync.RWMutex
}
func (pos *PromOptionsStruct) Set(datasourceId int64, po PromOption) {
pos.Lock()
pos.Data[datasourceId] = po
pos.Unlock()
}
func (pos *PromOptionsStruct) Del(datasourceId int64) {
pos.Lock()
delete(pos.Data, datasourceId)
pos.Unlock()
}
func (pos *PromOptionsStruct) Get(datasourceId int64) (PromOption, bool) {
pos.RLock()
defer pos.RUnlock()
ret, has := pos.Data[datasourceId]
return ret, has
}
// Data key is cluster name
var PromOptions = &PromOptionsStruct{Data: make(map[int64]PromOption)}