From c6d1beb0696ac5054c9b3de2c9dca9d375361452 Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Sat, 22 Jan 2022 20:11:10 -0500 Subject: [PATCH] Client now takes an interface, not a pointer --- client.go | 10 +++++----- client_test.go | 6 +++--- config.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client.go b/client.go index 92d0cf5..fc4a37c 100644 --- a/client.go +++ b/client.go @@ -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 } @@ -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 @@ -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) diff --git a/client_test.go b/client_test.go index dbdb9bd..78cd60c 100644 --- a/client_test.go +++ b/client_test.go @@ -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 } diff --git a/config.go b/config.go index 9da3abd..4d1c7ff 100644 --- a/config.go +++ b/config.go @@ -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