-
Notifications
You must be signed in to change notification settings - Fork 0
/
capability.go
154 lines (139 loc) · 3.11 KB
/
capability.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package proto
type Capability struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
MonitoringId string `json:"monitoringId,omitempty"`
Metric string `json:"metric,omitempty"`
View string `json:"view,omitempty"`
Thresholds uint64 `json:"thresholds,omitempty"`
Demux *[]string `json:"demux,omitempty"`
Constraints *[]CapabilityConstraint `json:"constraints,omitempty"`
Details *CapabilityDetails `json:"details,omitempty"`
}
type CapabilityFilter struct {
MonitoringId string `json:"monitoringId,omitempty"`
MonitoringName string `json:"monitoringName,omitempty"`
Metric string `json:"metric,omitempty"`
View string `json:"view,omitempty"`
}
type CapabilityConstraint struct {
Type string
Name string
Value string
}
type CapabilityDetails struct {
DetailsCreation
}
func (c *Capability) DeepCompare(a *Capability) bool {
if c.Id != a.Id {
return false
}
if c.Name != a.Name {
return false
}
if c.MonitoringId != a.MonitoringId {
return false
}
if c.Metric != a.Metric {
return false
}
if c.View != a.View {
return false
}
if c.Thresholds != a.Thresholds {
return false
}
/*
if c.Demux != nil {
demuxloop:
for _, str := range *c.Demux {
if c.DeepCompareSlice(str, a.Demux) {
continue demuxloop
}
return false
}
}
if a.Demux != nil {
revdemuxloop:
for _, str := range *a.Demux {
if c.DeepCompareSlice(str, c.Demux) {
continue revdemuxloop
}
return false
}
}
if c.Constraints != nil {
constraintloop:
for _, cstr := range *c.Constraints {
if cstr.DeepCompareSlice(a.Constraints) {
continue constraintloop
}
return false
}
}
if a.Constraints != nil {
revconstraintloop:
for _, cstr := range *a.Constraints {
if cstr.DeepCompareSlice(c.Constraints) {
continue revconstraintloop
}
return false
}
}
*/
return true
}
func (c *Capability) DeepCompareSlice(s string, a *[]string) bool {
if a == nil || *a == nil {
return false
}
for _, str := range *a {
if s == str {
return true
}
}
return false
}
func (c *CapabilityConstraint) DeepCompare(a *CapabilityConstraint) bool {
if a == nil {
return false
}
if c.Type != a.Type || c.Name != a.Type || c.Value != a.Value {
return false
}
return true
}
func (c *CapabilityConstraint) DeepCompareSlice(a *[]CapabilityConstraint) bool {
if a == nil || *a == nil {
return false
}
for _, cstr := range *a {
if c.DeepCompare(&cstr) {
return true
}
}
return false
}
func NewCapabilityRequest() Request {
return Request{
Flags: &Flags{},
Capability: &Capability{
Demux: &[]string{},
Constraints: &[]CapabilityConstraint{},
},
}
}
func NewCapabilityFilter() Request {
return Request{
Filter: &Filter{
Capability: &CapabilityFilter{},
},
}
}
func NewCapabilityResult() Result {
return Result{
Errors: &[]string{},
Capabilities: &[]Capability{},
}
}
// vim: ts=4 sw=4 sts=4 noet fenc=utf-8 ffs=unix