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 HTTPClient interface to Pusher struct #559

Merged
merged 2 commits into from
May 5, 2019
Merged

Conversation

nghialt
Copy link
Contributor

@nghialt nghialt commented Apr 26, 2019

Hi beorn@soundcloud.com,

I have a need to customize HTTP client but the lib only accept http.Client so I made this PR. Please review and comment.

Regards,
NghiaLT.

Signed-off-by: NghiaLT <nghialt.11@gmail.com>
@beorn7
Copy link
Member

beorn7 commented Apr 29, 2019

I like the idea in general. I will give this a proper review ASAP.

Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and my apologies for the delayed review. Code-wise, this looks good. I'd just suggest to not create a separate file for a one-method interface. There are also some naming and documentation changes that should help the user to understand what's going on.

import "net/http"

// HTTPClient is a interface for http client
type HTTPClient interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Let's not create a new file for a one-method interface. This interface is tightly coupled to the Pusher type. Let's put it into the same file.
  2. Let's call it HTTPDoer as it doesn't really represent a fully fledged http.Client.
  3. Suggested doc comment to tell the reader why we are doing all of this: // HTTPDoer is an interface for the one method of http.Client that is used by Pusher.

@@ -170,7 +170,7 @@ func (p *Pusher) Grouping(name, value string) *Pusher {

// Client sets a custom HTTP client for the Pusher. For convenience, this method
// returns a pointer to the Pusher itself.
func (p *Pusher) Client(c *http.Client) *Pusher {
func (p *Pusher) Client(c HTTPClient) *Pusher {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comment needs to be amended. Suggestion for additional text:

Pusher only needs one method of the custom HTTP client: Do(*http.Request). Thus, rather than requiring a fully fledged http.Client, the provided client only needs to implement the HTTPDoer interface. Since *http.Client naturally implements that interface, it can still be used normally.

Signed-off-by: NghiaLT <nghialt.11@gmail.com>
@nghialt
Copy link
Contributor Author

nghialt commented May 5, 2019

Agreed with your comments! I have updated accordingly, please check @beorn7.
Thanks for your time!

@beorn7
Copy link
Member

beorn7 commented May 5, 2019

Many thanks. Merging now.

@beorn7 beorn7 merged commit f1d50bc into prometheus:master May 5, 2019
@nghialt
Copy link
Contributor Author

nghialt commented May 6, 2019

by the way, when will the next release be @beorn7?

@beorn7
Copy link
Member

beorn7 commented May 7, 2019

I'm working on #539, #542, and #543. Once that's done, I'll cut a new release. Next week or so...

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

Successfully merging this pull request may close these issues.

None yet

2 participants