Skip to content

Commit 862df07

Browse files
committed
Add comments to client.go
1 parent cd8e450 commit 862df07

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

prometheus/promhttp/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ type httpClient interface {
3434
PostForm(string, url.Values) (*http.Response, error)
3535
}
3636

37+
// ClientMiddleware is an adapter to allow wrapping an http.Client or other
38+
// Middleware funcs, allowing the user to construct layers of middleware around
39+
// an http client request.
3740
type ClientMiddleware func(req *http.Request) (*http.Response, error)
3841

42+
// Do implements the httpClient interface.
3943
func (c ClientMiddleware) Do(r *http.Request) (*http.Response, error) {
4044
return c(r)
4145
}
4246

47+
// Get implements the httpClient interface.
4348
func (c ClientMiddleware) Get(url string) (resp *http.Response, err error) {
4449
req, err := http.NewRequest("GET", url, nil)
4550
if err != nil {
@@ -48,6 +53,7 @@ func (c ClientMiddleware) Get(url string) (resp *http.Response, err error) {
4853
return c.Do(req)
4954
}
5055

56+
// Head implements the httpClient interface.
5157
func (c ClientMiddleware) Head(url string) (*http.Response, error) {
5258
req, err := http.NewRequest("HEAD", url, nil)
5359
if err != nil {
@@ -56,6 +62,7 @@ func (c ClientMiddleware) Head(url string) (*http.Response, error) {
5662
return c.Do(req)
5763
}
5864

65+
// Post implements the httpClient interface.
5966
func (c ClientMiddleware) Post(url string, contentType string, body io.Reader) (*http.Response, error) {
6067
req, err := http.NewRequest("POST", url, body)
6168
if err != nil {
@@ -65,6 +72,7 @@ func (c ClientMiddleware) Post(url string, contentType string, body io.Reader) (
6572
return c.Do(req)
6673
}
6774

75+
// PostForm implements the httpClient interface.
6876
func (c ClientMiddleware) PostForm(url string, data url.Values) (*http.Response, error) {
6977
return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
7078
}

0 commit comments

Comments
 (0)