Skip to content

Commit

Permalink
Copy a new client inside WithRespHandler
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <ghzpotato@gmail.com>
  • Loading branch information
JmPotato committed Nov 21, 2023
1 parent d9e988c commit cd5397a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions client/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ func (c *client) Close() {
log.Info("[pd] http client closed")
}

// WithRespHandler sets the client with the given HTTP response handler.
// 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 {
c.respHandler = handler
return c
newClient := *c
newClient.respHandler = handler
return &newClient
}

func (c *client) reqCounter(name, status string) {
Expand Down

0 comments on commit cd5397a

Please sign in to comment.