-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2019 The Prometheus Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package push | ||
|
||
import "net/http" | ||
|
||
// HTTPClient is a interface for http client | ||
type HTTPClient interface { | ||
Do(*http.Request) (*http.Response, error) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ type Pusher struct { | |
gatherers prometheus.Gatherers | ||
registerer prometheus.Registerer | ||
|
||
client *http.Client | ||
client HTTPClient | ||
useBasicAuth bool | ||
username, password string | ||
|
||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
p.client = c | ||
return p | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pusher
type. Let's put it into the same file.HTTPDoer
as it doesn't really represent a fully fledgedhttp.Client
.// HTTPDoer is an interface for the one method of http.Client that is used by Pusher.