go-force
go-force copied to clipboard
Allow setting of custom *http.Client
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.
Ahhh, I see PR #39 addresses this but does so globally, not on a per client basis.
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
}
btw this is a good idea, IMO.