Skip to content

Commit

Permalink
Replace HTTPClient with HTTPDoer; Update document accordingly
Browse files Browse the repository at this point in the history
Signed-off-by: NghiaLT <nghialt.11@gmail.com>
  • Loading branch information
nghialt committed May 5, 2019
1 parent c9d7791 commit 11ad170
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
21 changes: 0 additions & 21 deletions prometheus/push/http.go

This file was deleted.

13 changes: 11 additions & 2 deletions prometheus/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ import (

const contentTypeHeader = "Content-Type"

// HTTPDoer is a interface for http client
type HTTPDoer interface {
Do(*http.Request) (*http.Response, error)
}

// Pusher manages a push to the Pushgateway. Use New to create one, configure it
// with its methods, and finally use the Add or Push method to push.
type Pusher struct {
Expand All @@ -61,7 +66,7 @@ type Pusher struct {
gatherers prometheus.Gatherers
registerer prometheus.Registerer

client HTTPClient
client HTTPDoer
useBasicAuth bool
username, password string

Expand Down Expand Up @@ -170,7 +175,11 @@ 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 HTTPClient) *Pusher {
// 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.
func (p *Pusher) Client(c HTTPDoer) *Pusher {
p.client = c
return p
}
Expand Down

0 comments on commit 11ad170

Please sign in to comment.