Skip to content

Commit

Permalink
Client now takes an interface, not a pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jan 23, 2022
1 parent 567b45b commit c6d1beb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"github.com/gojektech/heimdall/v6/httpclient"
)

// httpInterface is used for the http client (mocking heimdall)
type httpInterface interface {
// HTTPInterface is used for the http client (mocking heimdall)
type HTTPInterface interface {
Do(req *http.Request) (*http.Response, error)
}

// Client is the parent struct that contains the miner clients and list of miners to use
type Client struct {
httpClient httpInterface // Interface for all HTTP requests
httpClient HTTPInterface // Interface for all HTTP requests
Miners []*Miner // List of loaded miners
Options *ClientOptions // Client options config
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func DefaultClientOptions() (clientOptions *ClientOptions) {
// clientOptions: inject custom client options on load
// customHTTPClient: use your own custom HTTP client
// customMiners: use your own custom list of miners
func NewClient(clientOptions *ClientOptions, customHTTPClient *http.Client,
func NewClient(clientOptions *ClientOptions, customHTTPClient HTTPInterface,
customMiners []*Miner) (client *Client, err error) {

// Create the new client
Expand All @@ -165,7 +165,7 @@ func NewClient(clientOptions *ClientOptions, customHTTPClient *http.Client,
}

// createClient will make a new http client based on the options provided
func createClient(options *ClientOptions, customHTTPClient *http.Client) (c *Client) {
func createClient(options *ClientOptions, customHTTPClient HTTPInterface) (c *Client) {

// Create a client
c = new(Client)
Expand Down
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func (m *mockHTTPDefaultClient) Do(req *http.Request) (*http.Response, error) {
}

// newTestClient returns a client for mocking (using a custom HTTP interface)
func newTestClient(httpClient httpInterface) *Client {
client, _ := NewClient(nil, nil, nil)
client.httpClient = httpClient
func newTestClient(httpClient HTTPInterface) *Client {
client, _ := NewClient(nil, httpClient, nil)
// client.httpClient = httpClient
return client
}

Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "time"
const (

// version is the current package version
version = "v0.4.0"
version = "v0.5.0"

// defaultUserAgent is the default user agent for all requests
defaultUserAgent string = "go-minercraft: " + version
Expand Down

0 comments on commit c6d1beb

Please sign in to comment.