/
model_notification_rule_condition_serializer.go
81 lines (68 loc) · 2.48 KB
/
model_notification_rule_condition_serializer.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
package nextgen
import (
"encoding/json"
"fmt"
)
func (a *NotificationRuleCondition) UnmarshalJSON(data []byte) error {
type Alias NotificationRuleCondition
aux := &struct {
*Alias
}{
Alias: (*Alias)(a),
}
err := json.Unmarshal(data, &aux)
if err != nil {
return err
}
switch a.Type_ {
case NotificationRuleConditionTypes.ErrorBudgetRemainingPercentage:
err = json.Unmarshal(aux.Spec, &a.ErrorBudgetRemainingPercentage)
case NotificationRuleConditionTypes.ErrorBudgetRemainingMinutes:
err = json.Unmarshal(aux.Spec, &a.ErrorBudgetRemainingMinutes)
case NotificationRuleConditionTypes.ErrorBudgetBurnRate:
err = json.Unmarshal(aux.Spec, &a.ErrorBudgetBurnRate)
case NotificationRuleConditionTypes.ChangeImpact:
err = json.Unmarshal(aux.Spec, &a.ChangeImpact)
case NotificationRuleConditionTypes.HealthScore:
err = json.Unmarshal(aux.Spec, &a.HealthScore)
case NotificationRuleConditionTypes.ChangeObserved:
err = json.Unmarshal(aux.Spec, &a.ChangeObserved)
case NotificationRuleConditionTypes.CodeErrors:
err = json.Unmarshal(aux.Spec, &a.CodeErrors)
case NotificationRuleConditionTypes.DeploymentImpactReport:
err = json.Unmarshal(aux.Spec, &a.DeploymentImpactReport)
default:
panic(fmt.Sprintf("unknown notification rule condition type type %s", a.Type_))
}
return err
}
func (a *NotificationRuleCondition) MarshalJSON() ([]byte, error) {
type Alias NotificationRuleCondition
var spec []byte
var err error
switch a.Type_ {
case NotificationRuleConditionTypes.ErrorBudgetRemainingPercentage:
spec, err = json.Marshal(a.ErrorBudgetRemainingPercentage)
case NotificationRuleConditionTypes.ErrorBudgetRemainingMinutes:
spec, err = json.Marshal(a.ErrorBudgetRemainingMinutes)
case NotificationRuleConditionTypes.ErrorBudgetBurnRate:
spec, err = json.Marshal(a.ErrorBudgetBurnRate)
case NotificationRuleConditionTypes.ChangeImpact:
spec, err = json.Marshal(a.ChangeImpact)
case NotificationRuleConditionTypes.HealthScore:
spec, err = json.Marshal(a.HealthScore)
case NotificationRuleConditionTypes.ChangeObserved:
spec, err = json.Marshal(a.ChangeObserved)
case NotificationRuleConditionTypes.CodeErrors:
spec, err = json.Marshal(a.CodeErrors)
case NotificationRuleConditionTypes.DeploymentImpactReport:
spec, err = json.Marshal(a.DeploymentImpactReport)
default:
panic(fmt.Sprintf("unknown notification rule condition type type %s", a.Type_))
}
if err != nil {
return nil, err
}
a.Spec = json.RawMessage(spec)
return json.Marshal((*Alias)(a))
}