It was implemented as a method on Client, but the receiver was not used;
make it a regular function to prevent passing around the Client where
not needed.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -39,7 +39,7 @@ func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
|
| 39 | 39 |
switch resp.StatusCode {
|
| 40 | 40 |
case http.StatusOK, http.StatusInternalServerError: |
| 41 | 41 |
// Server handled the request, so parse the response |
| 42 |
- return parsePingResponse(cli, resp) |
|
| 42 |
+ return parsePingResponse(resp) |
|
| 43 | 43 |
} |
| 44 | 44 |
} |
| 45 | 45 |
|
| ... | ... |
@@ -50,17 +50,17 @@ func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
|
| 50 | 50 |
if err != nil {
|
| 51 | 51 |
return ping, err |
| 52 | 52 |
} |
| 53 |
- return parsePingResponse(cli, resp) |
|
| 53 |
+ return parsePingResponse(resp) |
|
| 54 | 54 |
} |
| 55 | 55 |
|
| 56 |
-func parsePingResponse(cli *Client, resp *http.Response) (types.Ping, error) {
|
|
| 56 |
+func parsePingResponse(resp *http.Response) (types.Ping, error) {
|
|
| 57 | 57 |
if resp == nil {
|
| 58 | 58 |
return types.Ping{}, nil
|
| 59 | 59 |
} |
| 60 | 60 |
|
| 61 | 61 |
var ping types.Ping |
| 62 | 62 |
if resp.Header == nil {
|
| 63 |
- return ping, cli.checkResponseErr(resp) |
|
| 63 |
+ return ping, checkResponseErr(resp) |
|
| 64 | 64 |
} |
| 65 | 65 |
ping.APIVersion = resp.Header.Get("Api-Version")
|
| 66 | 66 |
ping.OSType = resp.Header.Get("Ostype")
|
| ... | ... |
@@ -77,5 +77,5 @@ func parsePingResponse(cli *Client, resp *http.Response) (types.Ping, error) {
|
| 77 | 77 |
ControlAvailable: role == "manager", |
| 78 | 78 |
} |
| 79 | 79 |
} |
| 80 |
- return ping, cli.checkResponseErr(resp) |
|
| 80 |
+ return ping, checkResponseErr(resp) |
|
| 81 | 81 |
} |
| ... | ... |
@@ -127,7 +127,7 @@ func (cli *Client) sendRequest(ctx context.Context, method, path string, query u |
| 127 | 127 |
case errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded): |
| 128 | 128 |
return nil, err |
| 129 | 129 |
case err == nil: |
| 130 |
- return resp, cli.checkResponseErr(resp) |
|
| 130 |
+ return resp, checkResponseErr(resp) |
|
| 131 | 131 |
default: |
| 132 | 132 |
return resp, err |
| 133 | 133 |
} |
| ... | ... |
@@ -203,7 +203,7 @@ func (cli *Client) doRequest(req *http.Request) (*http.Response, error) {
|
| 203 | 203 |
return nil, errConnectionFailed{fmt.Errorf("error during connect: %w", err)}
|
| 204 | 204 |
} |
| 205 | 205 |
|
| 206 |
-func (cli *Client) checkResponseErr(serverResp *http.Response) (retErr error) {
|
|
| 206 |
+func checkResponseErr(serverResp *http.Response) (retErr error) {
|
|
| 207 | 207 |
if serverResp == nil {
|
| 208 | 208 |
return nil |
| 209 | 209 |
} |
| ... | ... |
@@ -39,7 +39,7 @@ func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
|
| 39 | 39 |
switch resp.StatusCode {
|
| 40 | 40 |
case http.StatusOK, http.StatusInternalServerError: |
| 41 | 41 |
// Server handled the request, so parse the response |
| 42 |
- return parsePingResponse(cli, resp) |
|
| 42 |
+ return parsePingResponse(resp) |
|
| 43 | 43 |
} |
| 44 | 44 |
} |
| 45 | 45 |
|
| ... | ... |
@@ -50,17 +50,17 @@ func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
|
| 50 | 50 |
if err != nil {
|
| 51 | 51 |
return ping, err |
| 52 | 52 |
} |
| 53 |
- return parsePingResponse(cli, resp) |
|
| 53 |
+ return parsePingResponse(resp) |
|
| 54 | 54 |
} |
| 55 | 55 |
|
| 56 |
-func parsePingResponse(cli *Client, resp *http.Response) (types.Ping, error) {
|
|
| 56 |
+func parsePingResponse(resp *http.Response) (types.Ping, error) {
|
|
| 57 | 57 |
if resp == nil {
|
| 58 | 58 |
return types.Ping{}, nil
|
| 59 | 59 |
} |
| 60 | 60 |
|
| 61 | 61 |
var ping types.Ping |
| 62 | 62 |
if resp.Header == nil {
|
| 63 |
- return ping, cli.checkResponseErr(resp) |
|
| 63 |
+ return ping, checkResponseErr(resp) |
|
| 64 | 64 |
} |
| 65 | 65 |
ping.APIVersion = resp.Header.Get("Api-Version")
|
| 66 | 66 |
ping.OSType = resp.Header.Get("Ostype")
|
| ... | ... |
@@ -77,5 +77,5 @@ func parsePingResponse(cli *Client, resp *http.Response) (types.Ping, error) {
|
| 77 | 77 |
ControlAvailable: role == "manager", |
| 78 | 78 |
} |
| 79 | 79 |
} |
| 80 |
- return ping, cli.checkResponseErr(resp) |
|
| 80 |
+ return ping, checkResponseErr(resp) |
|
| 81 | 81 |
} |
| ... | ... |
@@ -127,7 +127,7 @@ func (cli *Client) sendRequest(ctx context.Context, method, path string, query u |
| 127 | 127 |
case errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded): |
| 128 | 128 |
return nil, err |
| 129 | 129 |
case err == nil: |
| 130 |
- return resp, cli.checkResponseErr(resp) |
|
| 130 |
+ return resp, checkResponseErr(resp) |
|
| 131 | 131 |
default: |
| 132 | 132 |
return resp, err |
| 133 | 133 |
} |
| ... | ... |
@@ -203,7 +203,7 @@ func (cli *Client) doRequest(req *http.Request) (*http.Response, error) {
|
| 203 | 203 |
return nil, errConnectionFailed{fmt.Errorf("error during connect: %w", err)}
|
| 204 | 204 |
} |
| 205 | 205 |
|
| 206 |
-func (cli *Client) checkResponseErr(serverResp *http.Response) (retErr error) {
|
|
| 206 |
+func checkResponseErr(serverResp *http.Response) (retErr error) {
|
|
| 207 | 207 |
if serverResp == nil {
|
| 208 | 208 |
return nil |
| 209 | 209 |
} |