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

57
models/response.go Normal file
View File

@@ -0,0 +1,57 @@
package models
type Response struct {
Error bool `json:"error,omitempty"`
Message string `json:"message,omitempty"`
Get []Get `json:"get,omitempty"`
Set []Set `json:"set,omitempty"`
Subscribe []Subscribe `json:"subscribe,omitempty"`
Unsubscribe []Subscribe `json:"unsubscribe,omitempty"`
Publish []Publish `json:"publish,omitempty"`
}
func NewResponse() *Response {
return &Response{}
}
func (r *Response) SendError(msg string) {
r.Error = true
r.Message = msg
}
func (r *Response) AddGet(get Get) {
get.Query = nil
r.Get = append(r.Get, get)
}
func (r *Response) AddSet(set Set) {
r.Set = append(r.Set, set)
}
func (r *Response) AddSubscription(sub Subscribe) {
r.Subscribe = append(r.Subscribe, sub)
}
func (r *Response) IsValid() bool {
return !r.Error
}
func (r *Response) FetchGets() []Get {
return r.Get
}
func (r *Response) FetchSets() []Set {
return r.Set
}
func (r *Response) FetchSubscribes() []Subscribe {
return r.Subscribe
}
func (r *Response) FetchUnubscribes() []Subscribe {
return r.Unsubscribe
}
func (r *Response) FetchPublish() []Publish {
return r.Publish
}