add parse functons with io reader
This commit is contained in:
21
request.go
21
request.go
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user