forked from machadovilaca/monitoring-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalert_rule_classification_patch.go
More file actions
66 lines (61 loc) · 2.02 KB
/
alert_rule_classification_patch.go
File metadata and controls
66 lines (61 loc) · 2.02 KB
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
package managementrouter
import "encoding/json"
// AlertRuleClassificationPatch represents a partial update ("patch") payload for
// alert rule classification labels.
//
// This type supports a three-state contract per field:
// - omitted: leave unchanged
// - null: clear the override
// - string: set the override
//
// Note: Go's encoding/json cannot represent "explicit null" vs "omitted" using **string
// (both decode to nil), so we custom-unmarshal and track key presence with *Set flags.
type AlertRuleClassificationPatch struct {
Component *string `json:"openshift_io_alert_rule_component,omitempty"`
ComponentSet bool `json:"-"`
Layer *string `json:"openshift_io_alert_rule_layer,omitempty"`
LayerSet bool `json:"-"`
ComponentFrom *string `json:"openshift_io_alert_rule_component_from,omitempty"`
ComponentFromSet bool `json:"-"`
LayerFrom *string `json:"openshift_io_alert_rule_layer_from,omitempty"`
LayerFromSet bool `json:"-"`
}
func (p *AlertRuleClassificationPatch) UnmarshalJSON(b []byte) error {
var m map[string]json.RawMessage
if err := json.Unmarshal(b, &m); err != nil {
return err
}
decodeNullableString := func(key string) (set bool, v *string, err error) {
raw, ok := m[key]
if !ok {
return false, nil, nil
}
set = true
if len(raw) == 0 || string(raw) == "null" {
return true, nil, nil
}
var s string
if err := json.Unmarshal(raw, &s); err != nil {
return true, nil, err
}
return true, &s, nil
}
var err error
p.ComponentSet, p.Component, err = decodeNullableString("openshift_io_alert_rule_component")
if err != nil {
return err
}
p.LayerSet, p.Layer, err = decodeNullableString("openshift_io_alert_rule_layer")
if err != nil {
return err
}
p.ComponentFromSet, p.ComponentFrom, err = decodeNullableString("openshift_io_alert_rule_component_from")
if err != nil {
return err
}
p.LayerFromSet, p.LayerFrom, err = decodeNullableString("openshift_io_alert_rule_layer_from")
if err != nil {
return err
}
return nil
}