-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
package disk | ||
|
||
// TODO | ||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// func (c *Client) Status(ctx context.Context, operationId string, params *QueryParams) (*Operation, *ErrorResponse) { | ||
// return nil, nil | ||
// } | ||
// TODO: add tests and use generics instead of interface{} | ||
func (c *Client) OperationStatus(ctx context.Context, operationID string) (interface{}, *http.Response, error) { | ||
resp, err := c.doRequest(ctx, GET, fmt.Sprintf("operations/operation_id=%s", operationID), nil) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to make request: %w", err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
var errorResp ErrorResponse | ||
if err := json.NewDecoder(resp.Body).Decode(&errorResp); err != nil { | ||
return nil, resp, fmt.Errorf("failed to decode error response: %w", err) | ||
} | ||
return &errorResp, resp, nil | ||
} | ||
|
||
var operation Operation | ||
if err := json.NewDecoder(resp.Body).Decode(&operation); err != nil { | ||
return nil, resp, fmt.Errorf("failed to decode operation: %w", err) | ||
} | ||
|
||
return &operation, resp, nil | ||
} |