refactor: streamline response handling by introducing readResponseBody utility
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 22s

This commit is contained in:
2025-06-25 12:43:11 -04:00
parent f68538e66f
commit 51e03632ed
4 changed files with 32 additions and 25 deletions

26
client/response.go Normal file
View File

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