add comments and new parameter id for client request order
This commit is contained in:
@@ -1,68 +1,84 @@
|
||||
package models
|
||||
|
||||
// Response model
|
||||
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"`
|
||||
Id string `json:"id,omitempty"` // identification for requesting client
|
||||
Error bool `json:"error,omitempty"` // indicated response is a error
|
||||
Message string `json:"message,omitempty"` // response message
|
||||
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 Subscriptions
|
||||
Unsubscribe []Subscription `json:"unsubscribe,omitempty"` // collection of requested Unscubscriptions
|
||||
Publish []Publish `json:"publish,omitempty"` // collection of published data
|
||||
}
|
||||
|
||||
// Returns a new json_data Response model
|
||||
func NewResponse() *Response {
|
||||
return &Response{}
|
||||
}
|
||||
|
||||
func (r *Response) SendError(msg string) {
|
||||
// Set response as error
|
||||
func (r *Response) SetError() {
|
||||
r.Error = true
|
||||
}
|
||||
|
||||
// Set response message
|
||||
func (r *Response) SetMessage(msg string) {
|
||||
r.Message = msg
|
||||
}
|
||||
|
||||
func (r *Response) SendMessage(msg string) {
|
||||
r.Message = msg
|
||||
}
|
||||
|
||||
// Add new get to response collection
|
||||
func (r *Response) AddGet(get Get) {
|
||||
get.Query = nil
|
||||
r.Get = append(r.Get, get)
|
||||
}
|
||||
|
||||
// Add new set to response collection
|
||||
func (r *Response) AddSet(set Set) {
|
||||
r.Set = append(r.Set, set)
|
||||
}
|
||||
|
||||
func (r *Response) AddSubscription(sub Subscribe) {
|
||||
// Add new subscription to response collection
|
||||
func (r *Response) AddSubscription(sub Subscription) {
|
||||
r.Subscribe = append(r.Subscribe, sub)
|
||||
}
|
||||
|
||||
func (r *Response) AddUnsubscription(sub Subscribe) {
|
||||
// Add new unsubscribe to response collection
|
||||
func (r *Response) AddUnsubscription(sub Subscription) {
|
||||
r.Subscribe = append(r.Subscribe, sub)
|
||||
}
|
||||
|
||||
// Add new data publish to response
|
||||
func (r *Response) AddUPublish(pub Publish) {
|
||||
r.Publish = append(r.Publish, pub)
|
||||
}
|
||||
|
||||
// Check if response has a error
|
||||
func (r *Response) IsValid() bool {
|
||||
return !r.Error
|
||||
}
|
||||
|
||||
// Returns slice of get collection
|
||||
func (r *Response) FetchGets() []Get {
|
||||
return r.Get
|
||||
}
|
||||
|
||||
// Returns slice of set collection
|
||||
func (r *Response) FetchSets() []Set {
|
||||
return r.Set
|
||||
}
|
||||
|
||||
func (r *Response) FetchSubscribes() []Subscribe {
|
||||
// Returns slice of subscriptions collection
|
||||
func (r *Response) FetchSubscribes() []Subscription {
|
||||
return r.Subscribe
|
||||
}
|
||||
|
||||
func (r *Response) FetchUnubscribes() []Subscribe {
|
||||
// Returns slice of unsubscriptions collection
|
||||
func (r *Response) FetchUnubscribes() []Subscription {
|
||||
return r.Unsubscribe
|
||||
}
|
||||
|
||||
// Returns slice of published data
|
||||
func (r *Response) FetchPublish() []Publish {
|
||||
return r.Publish
|
||||
}
|
||||
|
Reference in New Issue
Block a user