Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client/http: pass res interface into respHandler #7404

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions client/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@
GetMinResolvedTSByStoresIDs(context.Context, []uint64) (uint64, map[uint64]uint64, error)

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

Expand All @@ -80,7 +84,7 @@
tlsConf *tls.Config
cli *http.Client

respHandler func(resp *http.Response) error
respHandler func(resp *http.Response, res interface{}) error

requestCounter *prometheus.CounterVec
executionDuration *prometheus.HistogramVec
Expand Down Expand Up @@ -160,8 +164,9 @@
}

// WithRespHandler sets and returns a new client with the given HTTP response handler.
// This allows the caller to customize how the response is handled, including error handling logic.
func (c *client) WithRespHandler(handler func(resp *http.Response) error) Client {
func (c *client) WithRespHandler(
handler func(resp *http.Response, res interface{}) error,
) Client {

Check warning on line 169 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L169

Added line #L169 was not covered by tests
newClient := *c
newClient.respHandler = handler
return &newClient
Expand Down Expand Up @@ -231,7 +236,7 @@

// Give away the response handling to the caller if the handler is set.
if c.respHandler != nil {
return c.respHandler(resp)
return c.respHandler(resp, res)

Check warning on line 239 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L239

Added line #L239 was not covered by tests
}

defer func() {
Expand Down
Loading