-
Notifications
You must be signed in to change notification settings - Fork 69
/
contracts.go
46 lines (37 loc) · 1.12 KB
/
contracts.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package edgeworkers
import (
"context"
"errors"
"fmt"
"net/http"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session"
)
type (
// ListContractsResponse represents a response object returned by ListContracts
ListContractsResponse struct {
ContractIDs []string `json:"contractIds"`
}
)
var (
// ErrListContracts is returned in case an error occurs on ListContracts operation
ErrListContracts = errors.New("list contracts")
)
func (e *edgeworkers) ListContracts(ctx context.Context) (*ListContractsResponse, error) {
logger := e.Log(ctx)
logger.Debug("ListContracts")
uri := "/edgeworkers/v1/contracts"
req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, fmt.Errorf("%w: failed to create request: %s", ErrListContracts, err)
}
var result ListContractsResponse
resp, err := e.Exec(req, &result)
if err != nil {
return nil, fmt.Errorf("%w: request failed: %s", ErrListContracts, err)
}
defer session.CloseResponseBody(resp)
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%s: %w", ErrListContracts, e.Error(resp))
}
return &result, nil
}