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

Add an interface for http.Client #16047

Closed
Dynom opened this issue Jun 13, 2016 · 2 comments
Closed

Add an interface for http.Client #16047

Dynom opened this issue Jun 13, 2016 · 2 comments

Comments

@Dynom
Copy link

Dynom commented Jun 13, 2016

TL;DR I'm trying to add some robustness to web service requests, but I find it very difficult to add this without an interface for http.Client.

To sketch the situation:

  • This factory (google-api-go-client Translate) requires an http.Client as argument.
  • This library wraps http.Client to provide all sorts of great features for adding robustness.
  • Because Go doesn't offer an interface type for http.Client, only concrete types can be used and thus there is no (sensible) way to use pester.Client even though it is a drop-in replacement for http.Client.

What I've done so far

  • I've searched for an interface that can be used by the Translate SDK so that it can be changed to accept a custom concrete type, but I didn't find any.

A related thread: googleapis/google-api-go-client#142 (comment)

@ianlancetaylor
Copy link
Contributor

The place to fix this is google-api-go-client.

Adding an interface for http.Client in the http package does not seem right. That suggests that other people will want to implement the interface. Since they will do, it will be impossible for us in practice to add new methods to the http.Client interface, since that would break other packages.

Instead, packages that want to use http.Client, and want to permit wrapping, should define their own interface, and use it.

Closing because I don't think there is anything to do in the Go standard library.

@Dynom
Copy link
Author

Dynom commented Jun 14, 2016

Alright, thanks for the explanation.

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

No branches or pull requests

3 participants