-
Notifications
You must be signed in to change notification settings - Fork 28
/
visibility_gen.go
65 lines (55 loc) · 1.37 KB
/
visibility_gen.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
// GENERATED. DO NOT MODIFY!
package types
import (
"encoding/json"
"github.com/Peripli/service-manager/pkg/util"
"github.com/Peripli/service-manager/pkg/web"
)
const VisibilityType ObjectType = web.VisibilitiesURL
type Visibilities struct {
Visibilities []*Visibility `json:"visibilities"`
}
func (e *Visibilities) Add(object Object) {
e.Visibilities = append(e.Visibilities, object.(*Visibility))
}
func (e *Visibilities) ItemAt(index int) Object {
return e.Visibilities[index]
}
func (e *Visibilities) Len() int {
return len(e.Visibilities)
}
func (e *Visibility) GetType() ObjectType {
return VisibilityType
}
// MarshalJSON override json serialization for http response
func (e *Visibility) MarshalJSON() ([]byte, error) {
type E Visibility
toMarshal := struct {
*E
CreatedAt *string `json:"created_at,omitempty"`
UpdatedAt *string `json:"updated_at,omitempty"`
Labels Labels `json:"labels,omitempty"`
}{
E: (*E)(e),
Labels: e.Labels,
}
if !e.CreatedAt.IsZero() {
str := util.ToRFCNanoFormat(e.CreatedAt)
toMarshal.CreatedAt = &str
}
if !e.UpdatedAt.IsZero() {
str := util.ToRFCNanoFormat(e.UpdatedAt)
toMarshal.UpdatedAt = &str
}
hasNoLabels := true
for key, values := range e.Labels {
if key != "" && len(values) != 0 {
hasNoLabels = false
break
}
}
if hasNoLabels {
toMarshal.Labels = nil
}
return json.Marshal(toMarshal)
}