29 lines
528 B
Go
29 lines
528 B
Go
package tecaminodbmjson_data
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
|
|
"github.com/tecamino/tecamino-json_data/models"
|
|
)
|
|
|
|
// Returns a new json_data Response model
|
|
func NewResponse() *models.Response {
|
|
return &models.Response{}
|
|
}
|
|
|
|
// Parses the response body of a http or web socket request
|
|
func ParseResponse(body io.ReadCloser) (*models.Response, error) {
|
|
b, err := io.ReadAll(body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
r := models.Response{}
|
|
|
|
err = json.Unmarshal(b, &r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &r, nil
|
|
}
|