-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.go
32 lines (27 loc) · 911 Bytes
/
operations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package disk
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
// 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
}