Skip to content

Commit f181920

Browse files
committed
Pass res interface into respHandler
Signed-off-by: JmPotato <[email protected]>
1 parent 2349f01 commit f181920

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Diff for: client/http/client.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ type Client interface {
6969
GetMinResolvedTSByStoresIDs(context.Context, []uint64) (uint64, map[uint64]uint64, error)
7070

7171
/* Client-related methods */
72-
WithRespHandler(func(resp *http.Response) error) Client
72+
// WithRespHandler sets and returns a new client with the given HTTP response handler.
73+
// This allows the caller to customize how the response is handled, including error handling logic.
74+
// Additionally, it is important for the caller to handle the content of the response body properly
75+
// in order to ensure that it can be read and marshaled correctly into `res`.
76+
WithRespHandler(func(resp *http.Response, res interface{}) error) Client
7377
Close()
7478
}
7579

@@ -80,7 +84,7 @@ type client struct {
8084
tlsConf *tls.Config
8185
cli *http.Client
8286

83-
respHandler func(resp *http.Response) error
87+
respHandler func(resp *http.Response, res interface{}) error
8488

8589
requestCounter *prometheus.CounterVec
8690
executionDuration *prometheus.HistogramVec
@@ -161,7 +165,9 @@ func (c *client) Close() {
161165

162166
// WithRespHandler sets and returns a new client with the given HTTP response handler.
163167
// This allows the caller to customize how the response is handled, including error handling logic.
164-
func (c *client) WithRespHandler(handler func(resp *http.Response) error) Client {
168+
func (c *client) WithRespHandler(
169+
handler func(resp *http.Response, res interface{}) error,
170+
) Client {
165171
newClient := *c
166172
newClient.respHandler = handler
167173
return &newClient
@@ -231,7 +237,7 @@ func (c *client) request(
231237

232238
// Give away the response handling to the caller if the handler is set.
233239
if c.respHandler != nil {
234-
return c.respHandler(resp)
240+
return c.respHandler(resp, res)
235241
}
236242

237243
defer func() {

0 commit comments

Comments
 (0)