remodel json data for compatibility
This commit is contained in:
56
models/request.go
Normal file
56
models/request.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package models
|
||||
|
||||
type Request struct {
|
||||
Get []Get `json:"get,omitempty"`
|
||||
Set []Set `json:"set,omitempty"`
|
||||
Subscribe []Subscribe `json:"subscribe,omitempty"`
|
||||
Unsubscribe []Subscribe `json:"unsubscribe,omitempty"`
|
||||
}
|
||||
|
||||
func (r *Request) AddGet() *Get {
|
||||
get := Get{}
|
||||
r.Get = append(r.Get, get)
|
||||
return &get
|
||||
}
|
||||
|
||||
func (r *Request) AddSet() *Set {
|
||||
set := Set{}
|
||||
r.Set = append(r.Set, set)
|
||||
return &set
|
||||
}
|
||||
|
||||
func (r *Request) AddSubscription(path string, depth uint, onCreate, onChange, onDelete bool) {
|
||||
r.Subscribe = append(r.Subscribe, Subscribe{
|
||||
Path: path,
|
||||
Depth: depth,
|
||||
OnCreate: onCreate,
|
||||
OnDelete: onChange,
|
||||
OnChange: onDelete,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Request) AddDriverSubscription(path, driverName string, depth uint, onCreate, onChange, onDelete bool) {
|
||||
r.Subscribe = append(r.Subscribe, Subscribe{
|
||||
Path: path,
|
||||
Depth: depth,
|
||||
Driver: driverName,
|
||||
OnCreate: onCreate,
|
||||
OnDelete: onChange,
|
||||
OnChange: onDelete,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Request) AddUnsubscribe(path string, depth uint) {
|
||||
r.Unsubscribe = append(r.Unsubscribe, Subscribe{
|
||||
Path: path,
|
||||
Depth: depth,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Request) AddUnsubscribeDriver(path, driverName string, depth uint) {
|
||||
r.Unsubscribe = append(r.Unsubscribe, Subscribe{
|
||||
Path: path,
|
||||
Depth: depth,
|
||||
Driver: driverName,
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user