remodel json data for compatibility

This commit is contained in:
Adrian Zürcher
2025-04-26 23:14:50 +02:00
parent 85bd8de2a2
commit ea4719ff01
26 changed files with 672 additions and 550 deletions

56
models/request.go Normal file
View 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,
})
}