-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperations.go
More file actions
35 lines (30 loc) · 951 Bytes
/
operations.go
File metadata and controls
35 lines (30 loc) · 951 Bytes
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
33
34
35
package disk
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
)
// TODO: add tests and use generics instead of interface{}
func (c *Client) OperationStatus(ctx context.Context, operationID string) (any, *http.Response, error) {
query := url.Values{}
query.Set("operation_id", operationID)
resp, err := c.doRequest(ctx, GET, "operations?"+query.Encode(), 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
}