You've already forked email-api-client
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 19s
27 lines
396 B
Go
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
|
|
}
|