value.go 663 字节
Newer Older
Y
Your Name 已提交
1
package monitorkey
E
eoLinker API Management 已提交
2

Y
Your Name 已提交
3
//MonitorValues monitorValues
E
eoLinker API Management 已提交
4 5
type MonitorValues []int64

Y
Your Name 已提交
6
//Add add
Y
Your Name 已提交
7
func (a MonitorValues) Add(key MonitorKeyType) {
E
eoLinker API Management 已提交
8
	index := int(key)
Y
Your Name 已提交
9
	if index < len(a) {
E
eoLinker API Management 已提交
10 11 12
		a[index]++
	}
}
Y
Your Name 已提交
13 14

//Get get
Y
Your Name 已提交
15 16
func (a MonitorValues) Get(key MonitorKeyType) int64 {
	if a == nil {
E
eoLinker API Management 已提交
17 18 19
		return 0
	}
	index := int(key)
Y
Your Name 已提交
20
	if index < len(a) {
E
eoLinker API Management 已提交
21 22 23 24
		return a[index]
	}
	return 0
}
Y
Your Name 已提交
25 26

//Append append
Y
Your Name 已提交
27
func (a MonitorValues) Append(args ...MonitorValues) {
E
eoLinker API Management 已提交
28 29 30 31
	if len(args) == 0 {
		return
	}

Y
Your Name 已提交
32
	for _, arg := range args {
E
eoLinker API Management 已提交
33

Y
Your Name 已提交
34 35
		for i := range arg {
			a[i] += arg[i]
E
eoLinker API Management 已提交
36 37 38 39 40
		}
	}
	return
}

Y
Your Name 已提交
41
//MakeValue make value
E
eoLinker API Management 已提交
42
func MakeValue() MonitorValues {
Y
Your Name 已提交
43 44
	return make(MonitorValues, MonitorKeyTypeSize)
}