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

Allow setting of custom *http.Client #44

Open
someone1 opened this issue Dec 27, 2016 · 3 comments
Open

Allow setting of custom *http.Client #44

someone1 opened this issue Dec 27, 2016 · 3 comments

Comments

@someone1
Copy link

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
Copy link
Author

someone1 commented Dec 27, 2016

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

@rickb777
Copy link

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
Copy link

btw this is a good idea, IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants