go-force icon indicating copy to clipboard operation
go-force copied to clipboard

Allow setting of custom *http.Client

Open someone1 opened this issue 8 years ago • 3 comments

Due to various reasons, the http.DefaultClient used by default might not be appropriate to use. It would be nice to be able to specify what client to use for requests.

someone1 avatar Dec 27 '16 17:12 someone1

Ahhh, I see PR #39 addresses this but does so globally, not on a per client basis.

someone1 avatar Dec 27 '16 17:12 someone1

ForceApi could include a *http.Client value that is initialised in Create to http.DefaultClient.

type ForceApi struct {
	... existing
	httpClient *http.Client
}

Then change func (forceApi *ForceApi) request(...) error { to use the specified client instead of http.DefaultClient.

Then add a setup method

// WithHttpClient sets a specialised HTTP client to replace the default client for HTTP requests.
func (forceApi *ForceApi) WithHttpClient(c *http.Client) *ForceApi {
	forceApi.httpClient = c
	return forceApi
}

rickb777 avatar Oct 22 '20 11:10 rickb777

btw this is a good idea, IMO.

rickb777 avatar Oct 22 '20 11:10 rickb777