value.go 573 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3 4
package monitor_key

type MonitorValues []int64

Y
Your Name 已提交
5
func (a MonitorValues) Add(key MonitorKeyType) {
E
eoLinker API Management 已提交
6
	index := int(key)
Y
Your Name 已提交
7
	if index < len(a) {
E
eoLinker API Management 已提交
8 9 10
		a[index]++
	}
}
Y
Your Name 已提交
11 12
func (a MonitorValues) Get(key MonitorKeyType) int64 {
	if a == nil {
E
eoLinker API Management 已提交
13 14 15
		return 0
	}
	index := int(key)
Y
Your Name 已提交
16
	if index < len(a) {
E
eoLinker API Management 已提交
17 18 19 20
		return a[index]
	}
	return 0
}
Y
Your Name 已提交
21
func (a MonitorValues) Append(args ...MonitorValues) {
E
eoLinker API Management 已提交
22 23 24 25
	if len(args) == 0 {
		return
	}

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

Y
Your Name 已提交
28 29
		for i := range arg {
			a[i] += arg[i]
E
eoLinker API Management 已提交
30 31 32 33 34 35
		}
	}
	return
}

func MakeValue() MonitorValues {
Y
Your Name 已提交
36 37
	return make(MonitorValues, MonitorKeyTypeSize)
}