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

@@ -1,7 +1,26 @@
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 {
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
}