add comments and new parameter id for client request order

This commit is contained in:
Adrian Zuercher
2025-05-04 20:55:58 +02:00
parent c7154f0779
commit e3487eb340
15 changed files with 119 additions and 79 deletions

View File

@@ -1,26 +1,36 @@
package models
// Request model
type Request struct {
Get []Get `json:"get,omitempty"`
Set []Set `json:"set,omitempty"`
Subscribe []Subscribe `json:"subscribe,omitempty"`
Unsubscribe []Subscribe `json:"unsubscribe,omitempty"`
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, Subscribe{
r.Subscribe = append(r.Subscribe, Subscription{
Path: path,
Depth: depth,
OnCreate: onCreate,
@@ -29,8 +39,9 @@ func (r *Request) AddSubscription(path string, depth uint, onCreate, onChange, o
})
}
// 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, Subscribe{
r.Subscribe = append(r.Subscribe, Subscription{
Path: path,
Depth: depth,
Driver: driverName,
@@ -40,15 +51,17 @@ func (r *Request) AddDriverSubscription(path, driverName string, depth uint, onC
})
}
// Add new unsubsciption to request collection
func (r *Request) AddUnsubscribe(path string, depth uint) {
r.Unsubscribe = append(r.Unsubscribe, Subscribe{
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, Subscribe{
r.Unsubscribe = append(r.Unsubscribe, Subscription{
Path: path,
Depth: depth,
Driver: driverName,