Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
240f4fb3e7 | ||
|
|
bf36b023d3 | ||
|
|
a8127cc381 |
@@ -19,6 +19,10 @@ func (r *Response) SendError(msg string) {
|
|||||||
r.Message = msg
|
r.Message = msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Response) SendMessage(msg string) {
|
||||||
|
r.Message = msg
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Response) AddGet(get Get) {
|
func (r *Response) AddGet(get Get) {
|
||||||
get.Query = nil
|
get.Query = nil
|
||||||
r.Get = append(r.Get, get)
|
r.Get = append(r.Get, get)
|
||||||
@@ -32,6 +36,13 @@ func (r *Response) AddSubscription(sub Subscribe) {
|
|||||||
r.Subscribe = append(r.Subscribe, sub)
|
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 {
|
func (r *Response) IsValid() bool {
|
||||||
return !r.Error
|
return !r.Error
|
||||||
}
|
}
|
||||||
|
|||||||
21
request.go
21
request.go
@@ -1,7 +1,26 @@
|
|||||||
package tecaminodbmjson_data
|
package tecaminodbmjson_data
|
||||||
|
|
||||||
import "github.com/tecamino/tecamino-json_data/models"
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/tecamino/tecamino-json_data/models"
|
||||||
|
)
|
||||||
|
|
||||||
func NewRequest() *models.Request {
|
func NewRequest() *models.Request {
|
||||||
return &models.Request{}
|
return &models.Request{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseRequest(body io.ReadCloser) (*models.Request, error) {
|
||||||
|
b, err := io.ReadAll(body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r := models.Request{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(b, &r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &r, nil
|
||||||
|
}
|
||||||
|
|||||||
13
response.go
13
response.go
@@ -2,14 +2,23 @@ package tecaminodbmjson_data
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/tecamino/tecamino-json_data/models"
|
"github.com/tecamino/tecamino-json_data/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseResponse(b []byte) (*models.Response, error) {
|
func NewResponse() *models.Response {
|
||||||
|
return &models.Response{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseResponse(body io.ReadCloser) (*models.Response, error) {
|
||||||
|
b, err := io.ReadAll(body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
r := models.Response{}
|
r := models.Response{}
|
||||||
|
|
||||||
err := json.Unmarshal(b, &r)
|
err = json.Unmarshal(b, &r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user