add parse functons with io reader

This commit is contained in:
Adrian Zürcher
2025-04-27 16:04:33 +02:00
parent bf36b023d3
commit 240f4fb3e7
2 changed files with 27 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package tecaminodbmjson_data
import (
"encoding/json"
"io"
"github.com/tecamino/tecamino-json_data/models"
)
@@ -10,10 +11,14 @@ func NewResponse() *models.Response {
return &models.Response{}
}
func ParseResponse(b []byte) (*models.Response, error) {
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)
err = json.Unmarshal(b, &r)
if err != nil {
return nil, err
}