Skip to content

Commit

Permalink
use the Doer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
darshanime committed Mar 21, 2018
1 parent b496d1f commit b3d0767
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import (
"net/http"
)

// Doer interface has the method required to use a type as custom http client.
// The net/*http.Client type satisfies this interface.
type Doer interface {
Do(*http.Request) (*http.Response, error)
}

// Client Is a generic HTTP client interface
type Client interface {
Get(url string, headers http.Header) (*http.Response, error)
Expand All @@ -16,4 +22,5 @@ type Client interface {

SetRetryCount(count int)
SetRetrier(retrier Retriable)
SetCustomHTTPClient(customHTTPClient Doer)
}
8 changes: 7 additions & 1 deletion http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import (

const defaultRetryCount int = 0

// Doer defines the method required to use a type as HttpClient.
// The net/*http.Client type satisfies this interface.
type Doer interface {
Do(*http.Request) (*http.Response, error)
}

type httpClient struct {
client *http.Client
client Doer

retryCount int
retrier Retriable
Expand Down

0 comments on commit b3d0767

Please sign in to comment.