/
spec.go
66 lines (61 loc) · 1.59 KB
/
spec.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
// Copyright (c) 2021 Terminus, Inc.
//
// This program is free software: you can use, redistribute, and/or modify
// it under the terms of the GNU Affero General Public License, version 3
// or later ("AGPL"), as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package schemonjob
type StatusForEventbox struct {
// runtime namespace
Namespace string `json:"namespace"`
// runtime name
Name string `json:"name"`
// the "nofity" get the status and post it to this url
Addr []string `json:"addrs"`
// runtime status
Status string `json:"status,omitempty"`
// 扩展字段,比如存储runtime下每个服务的名字及状态
More map[string]string `json:"more,omitempty"`
}
// true if same
func Diff(j1, j2 *StatusForEventbox) bool {
if j1.Status != j2.Status || !mapDiff(j1.More, j2.More) || !sliceDiff(j1.Addr, j2.Addr) {
return false
}
return true
}
// true if same
func mapDiff(m1, m2 map[string]string) bool {
for k1, v1 := range m1 {
v2, ok := m2[k1]
if !ok {
return false
}
if v1 != v2 {
return false
}
}
return true
}
// true if same
func sliceDiff(s1, s2 []string) bool {
for _, v1 := range s1 {
flag := false
for _, v2 := range s2 {
if v1 == v2 {
flag = true
break
}
}
if !flag {
return false
}
}
return true
}