/
pingpair.go
129 lines (95 loc) · 2.59 KB
/
pingpair.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
package gaia
import (
"fmt"
"github.com/globalsign/mgo/bson"
"github.com/mitchellh/copystructure"
"go.aporeto.io/elemental"
)
// PingPair represents the model of a pingpair
type PingPair struct {
// Contains the request probe information.
Request *PingProbe `json:"request" msgpack:"request" bson:"request" mapstructure:"request,omitempty"`
// Contains the response probe information.
Response *PingProbe `json:"response" msgpack:"response" bson:"response" mapstructure:"response,omitempty"`
ModelVersion int `json:"-" msgpack:"-" bson:"_modelversion"`
}
// NewPingPair returns a new *PingPair
func NewPingPair() *PingPair {
return &PingPair{
ModelVersion: 1,
}
}
// GetBSON implements the bson marshaling interface.
// This is used to transparently convert ID to MongoDBID as ObectID.
func (o *PingPair) GetBSON() (interface{}, error) {
if o == nil {
return nil, nil
}
s := &mongoAttributesPingPair{}
s.Request = o.Request
s.Response = o.Response
return s, nil
}
// SetBSON implements the bson marshaling interface.
// This is used to transparently convert ID to MongoDBID as ObectID.
func (o *PingPair) SetBSON(raw bson.Raw) error {
if o == nil {
return nil
}
s := &mongoAttributesPingPair{}
if err := raw.Unmarshal(s); err != nil {
return err
}
o.Request = s.Request
o.Response = s.Response
return nil
}
// BleveType implements the bleve.Classifier Interface.
func (o *PingPair) BleveType() string {
return "pingpair"
}
// DeepCopy returns a deep copy if the PingPair.
func (o *PingPair) DeepCopy() *PingPair {
if o == nil {
return nil
}
out := &PingPair{}
o.DeepCopyInto(out)
return out
}
// DeepCopyInto copies the receiver into the given *PingPair.
func (o *PingPair) DeepCopyInto(out *PingPair) {
target, err := copystructure.Copy(o)
if err != nil {
panic(fmt.Sprintf("Unable to deepcopy PingPair: %s", err))
}
*out = *target.(*PingPair)
}
// Validate valides the current information stored into the structure.
func (o *PingPair) Validate() error {
errors := elemental.Errors{}
requiredErrors := elemental.Errors{}
if o.Request != nil {
elemental.ResetDefaultForZeroValues(o.Request)
if err := o.Request.Validate(); err != nil {
errors = errors.Append(err)
}
}
if o.Response != nil {
elemental.ResetDefaultForZeroValues(o.Response)
if err := o.Response.Validate(); err != nil {
errors = errors.Append(err)
}
}
if len(requiredErrors) > 0 {
return requiredErrors
}
if len(errors) > 0 {
return errors
}
return nil
}
type mongoAttributesPingPair struct {
Request *PingProbe `bson:"request"`
Response *PingProbe `bson:"response"`
}