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
|
package ovsdb
import "encoding/json"
// MonitorSelect represents a monitor select according to RFC7047
type MonitorSelect struct {
initial *bool
insert *bool
delete *bool
modify *bool
}
// NewMonitorSelect returns a new MonitorSelect with the provided values
func NewMonitorSelect(initial, insert, delete, modify bool) *MonitorSelect {
return &MonitorSelect{
initial: &initial,
insert: &insert,
delete: &delete,
modify: &modify,
}
}
// NewDefaultMonitorSelect returns a new MonitorSelect with default values
func NewDefaultMonitorSelect() *MonitorSelect {
return NewMonitorSelect(true, true, true, true)
}
// Initial returns whether or not an initial response will be sent
func (m MonitorSelect) Initial() bool {
if m.initial == nil {
return true
}
return *m.initial
}
// Insert returns whether we will receive updates for inserts
func (m MonitorSelect) Insert() bool {
if m.insert == nil {
return true
}
return *m.insert
}
// Delete returns whether we will receive updates for deletions
func (m MonitorSelect) Delete() bool {
if m.delete == nil {
return true
}
return *m.delete
}
// Modify returns whether we will receive updates for modifications
func (m MonitorSelect) Modify() bool {
if m.modify == nil {
return true
}
return *m.modify
}
type monitorSelect struct {
Initial *bool `json:"initial,omitempty"`
Insert *bool `json:"insert,omitempty"`
Delete *bool `json:"delete,omitempty"`
Modify *bool `json:"modify,omitempty"`
}
func (m MonitorSelect) MarshalJSON() ([]byte, error) {
ms := monitorSelect{
Initial: m.initial,
Insert: m.insert,
Delete: m.delete,
Modify: m.modify,
}
return json.Marshal(ms)
}
func (m *MonitorSelect) UnmarshalJSON(data []byte) error {
var ms monitorSelect
err := json.Unmarshal(data, &ms)
if err != nil {
return err
}
m.initial = ms.Initial
m.insert = ms.Insert
m.delete = ms.Delete
m.modify = ms.Modify
return nil
}
|