Files
tecamino-json_data/models/response.go
2025-04-27 09:51:32 +02:00

69 lines
1.4 KiB
Go

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) SendMessage(msg string) {
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) AddUnsubscription(sub Subscribe) {
r.Subscribe = append(r.Subscribe, sub)
}
func (r *Response) AddUPublish(pub Publish) {
r.Publish = append(r.Publish, pub)
}
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
}