-
Notifications
You must be signed in to change notification settings - Fork 13
/
objective.go
160 lines (109 loc) · 3.95 KB
/
objective.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
155
156
157
158
159
160
package platformclientv2
import (
"time"
"github.com/leekchan/timeutil"
"encoding/json"
"strconv"
"strings"
)
// Objective
type Objective struct {
// Id - The globally unique identifier for the object.
Id *string `json:"id,omitempty"`
// TemplateId - The id of this objective's base template
TemplateId *string `json:"templateId,omitempty"`
// Zones - Objective zone specifies min,max points and values for the associated metric
Zones *[]Objectivezone `json:"zones,omitempty"`
// Enabled - A flag for whether this objective is enabled for the related metric
Enabled *bool `json:"enabled,omitempty"`
// MediaTypes - A list of media types for the metric
MediaTypes *[]string `json:"mediaTypes,omitempty"`
// Queues - A list of queues for the metric
Queues *[]Addressableentityref `json:"queues,omitempty"`
// Topics - A list of topic ids for detected topic metrics
Topics *[]Addressableentityref `json:"topics,omitempty"`
// TopicIdsFilterType - A filter type for topic Ids. It's only used for objectives with topicIds. Default filter behavior is \"or\".
TopicIdsFilterType *string `json:"topicIdsFilterType,omitempty"`
// DateStart - start date of the objective. Dates are represented as an ISO-8601 string. For example: yyyy-MM-dd
DateStart *time.Time `json:"dateStart,omitempty"`
}
func (o *Objective) MarshalJSON() ([]byte, error) {
// Redundant initialization to avoid unused import errors for models with no Time values
_ = timeutil.Timedelta{}
type Alias Objective
DateStart := new(string)
if o.DateStart != nil {
*DateStart = timeutil.Strftime(o.DateStart, "%Y-%m-%d")
} else {
DateStart = nil
}
return json.Marshal(&struct {
Id *string `json:"id,omitempty"`
TemplateId *string `json:"templateId,omitempty"`
Zones *[]Objectivezone `json:"zones,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
MediaTypes *[]string `json:"mediaTypes,omitempty"`
Queues *[]Addressableentityref `json:"queues,omitempty"`
Topics *[]Addressableentityref `json:"topics,omitempty"`
TopicIdsFilterType *string `json:"topicIdsFilterType,omitempty"`
DateStart *string `json:"dateStart,omitempty"`
*Alias
}{
Id: o.Id,
TemplateId: o.TemplateId,
Zones: o.Zones,
Enabled: o.Enabled,
MediaTypes: o.MediaTypes,
Queues: o.Queues,
Topics: o.Topics,
TopicIdsFilterType: o.TopicIdsFilterType,
DateStart: DateStart,
Alias: (*Alias)(o),
})
}
func (o *Objective) UnmarshalJSON(b []byte) error {
var ObjectiveMap map[string]interface{}
err := json.Unmarshal(b, &ObjectiveMap)
if err != nil {
return err
}
if Id, ok := ObjectiveMap["id"].(string); ok {
o.Id = &Id
}
if TemplateId, ok := ObjectiveMap["templateId"].(string); ok {
o.TemplateId = &TemplateId
}
if Zones, ok := ObjectiveMap["zones"].([]interface{}); ok {
ZonesString, _ := json.Marshal(Zones)
json.Unmarshal(ZonesString, &o.Zones)
}
if Enabled, ok := ObjectiveMap["enabled"].(bool); ok {
o.Enabled = &Enabled
}
if MediaTypes, ok := ObjectiveMap["mediaTypes"].([]interface{}); ok {
MediaTypesString, _ := json.Marshal(MediaTypes)
json.Unmarshal(MediaTypesString, &o.MediaTypes)
}
if Queues, ok := ObjectiveMap["queues"].([]interface{}); ok {
QueuesString, _ := json.Marshal(Queues)
json.Unmarshal(QueuesString, &o.Queues)
}
if Topics, ok := ObjectiveMap["topics"].([]interface{}); ok {
TopicsString, _ := json.Marshal(Topics)
json.Unmarshal(TopicsString, &o.Topics)
}
if TopicIdsFilterType, ok := ObjectiveMap["topicIdsFilterType"].(string); ok {
o.TopicIdsFilterType = &TopicIdsFilterType
}
if dateStartString, ok := ObjectiveMap["dateStart"].(string); ok {
DateStart, _ := time.Parse("2006-01-02", dateStartString)
o.DateStart = &DateStart
}
return nil
}
// String returns a JSON representation of the model
func (o *Objective) String() string {
j, _ := json.Marshal(o)
str, _ := strconv.Unquote(strings.Replace(strconv.Quote(string(j)), `\\u`, `\u`, -1))
return str
}