Files
tecamino-json_data/models/request.go
2025-04-26 23:14:50 +02:00

57 lines
1.3 KiB
Go

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,
})
}