|
95 | 95 | // SuccessHook type is for reacting to request success |
96 | 96 | SuccessHook func(*Client, *Response) |
97 | 97 |
|
98 | | - // CloseHook type is for reacting to client closing |
99 | | - CloseHook func() |
100 | | - |
101 | 98 | // RequestFunc type is for extended manipulation of the Request instance |
102 | 99 | RequestFunc func(*Request) *Request |
103 | 100 |
|
@@ -218,7 +215,6 @@ type Client struct { |
218 | 215 | invalidHooks []ErrorHook |
219 | 216 | panicHooks []ErrorHook |
220 | 217 | successHooks []SuccessHook |
221 | | - closeHooks []CloseHook |
222 | 218 | contentTypeEncoders map[string]ContentTypeEncoder |
223 | 219 | contentTypeDecoders map[string]ContentTypeDecoder |
224 | 220 | contentDecompresserKeys []string |
@@ -842,15 +838,6 @@ func (c *Client) OnPanic(h ErrorHook) *Client { |
842 | 838 | return c |
843 | 839 | } |
844 | 840 |
|
845 | | -// OnClose method adds a callback that will be run whenever the client is closed. |
846 | | -// The hooks are executed in the order they were registered. |
847 | | -func (c *Client) OnClose(h CloseHook) *Client { |
848 | | - c.lock.Lock() |
849 | | - defer c.lock.Unlock() |
850 | | - c.closeHooks = append(c.closeHooks, h) |
851 | | - return c |
852 | | -} |
853 | | - |
854 | 841 | // ContentTypeEncoders method returns all the registered content type encoders. |
855 | 842 | func (c *Client) ContentTypeEncoders() map[string]ContentTypeEncoder { |
856 | 843 | c.lock.RLock() |
@@ -2234,14 +2221,10 @@ func (c *Client) Clone(ctx context.Context) *Client { |
2234 | 2221 |
|
2235 | 2222 | // Close method performs cleanup and closure activities on the client instance |
2236 | 2223 | func (c *Client) Close() error { |
2237 | | - // Execute close hooks first |
2238 | | - c.onCloseHooks() |
2239 | | - |
2240 | 2224 | if c.LoadBalancer() != nil { |
2241 | 2225 | silently(c.LoadBalancer().Close()) |
2242 | 2226 | } |
2243 | 2227 | close(c.certWatcherStopChan) |
2244 | | - |
2245 | 2228 | return nil |
2246 | 2229 | } |
2247 | 2230 |
|
@@ -2398,15 +2381,6 @@ func (c *Client) onInvalidHooks(req *Request, err error) { |
2398 | 2381 | } |
2399 | 2382 | } |
2400 | 2383 |
|
2401 | | -// Helper to run closeHooks hooks. |
2402 | | -func (c *Client) onCloseHooks() { |
2403 | | - c.lock.RLock() |
2404 | | - defer c.lock.RUnlock() |
2405 | | - for _, h := range c.closeHooks { |
2406 | | - h() |
2407 | | - } |
2408 | | -} |
2409 | | - |
2410 | 2384 | func (c *Client) debugf(format string, v ...any) { |
2411 | 2385 | if c.IsDebug() { |
2412 | 2386 | c.Logger().Debugf(format, v...) |
|
0 commit comments