70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package models
|
|
|
|
// Request model
|
|
type Request struct {
|
|
Id string `json:"id,omitempty"` // identification from requesting client
|
|
Get []Get `json:"get,omitempty"` // collection of requested Gets
|
|
Set []Set `json:"set,omitempty"` // collection of requested Sets
|
|
Subscribe []Subscription `json:"subscribe,omitempty"` // collection of requested Subsciptions
|
|
Unsubscribe []Subscription `json:"unsubscribe,omitempty"` // collection of requested Unsubsciptions
|
|
}
|
|
|
|
// Returns a new json_data Request model
|
|
func NewRequest() *Request {
|
|
return &Request{}
|
|
}
|
|
|
|
// Add new get to request collection
|
|
func (r *Request) AddGet() *Get {
|
|
get := Get{}
|
|
r.Get = append(r.Get, get)
|
|
return &get
|
|
}
|
|
|
|
// Add new set to request collection
|
|
func (r *Request) AddSet() *Set {
|
|
set := Set{}
|
|
r.Set = append(r.Set, set)
|
|
return &set
|
|
}
|
|
|
|
// Add new subsciption to request collection
|
|
func (r *Request) AddSubscription(path string, depth uint, onCreate, onChange, onDelete bool) {
|
|
r.Subscribe = append(r.Subscribe, Subscription{
|
|
Path: path,
|
|
Depth: depth,
|
|
OnCreate: onCreate,
|
|
OnDelete: onChange,
|
|
OnChange: onDelete,
|
|
})
|
|
}
|
|
|
|
// Add new driver specific subsciption to request collection
|
|
func (r *Request) AddDriverSubscription(path, driverName string, depth uint, onCreate, onChange, onDelete bool) {
|
|
r.Subscribe = append(r.Subscribe, Subscription{
|
|
Path: path,
|
|
Depth: depth,
|
|
Driver: driverName,
|
|
OnCreate: onCreate,
|
|
OnDelete: onChange,
|
|
OnChange: onDelete,
|
|
})
|
|
}
|
|
|
|
// Add new unsubsciption to request collection
|
|
func (r *Request) AddUnsubscribe(path string, depth uint) {
|
|
r.Unsubscribe = append(r.Unsubscribe, Subscription{
|
|
Path: path,
|
|
Depth: depth,
|
|
})
|
|
}
|
|
|
|
// Add new driver unsubsciption to request collection
|
|
func (r *Request) AddUnsubscribeDriver(path, driverName string, depth uint) {
|
|
r.Unsubscribe = append(r.Unsubscribe, Subscription{
|
|
Path: path,
|
|
Depth: depth,
|
|
Driver: driverName,
|
|
})
|
|
}
|