Files
email-api-client/client/response.go
Ron Rise 1bd826f949
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 19s
refactor: fix json.Unmarshal target reference in response handling
2025-06-25 12:45:20 -04:00

27 lines
396 B
Go

package client
import (
"encoding/json"
"io"
"net/http"
)
func readResponseBody[T any](res *http.Response) (*T, error) {
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(res.Body)
responseBody, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
var target T
err = json.Unmarshal(responseBody, &target)
if err != nil {
return nil, err
}
return &target, nil
}