-
Notifications
You must be signed in to change notification settings - Fork 2
/
available_extension.go
56 lines (46 loc) · 1.59 KB
/
available_extension.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
47
48
49
50
51
52
53
54
55
56
package dbaas
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
// AvailableExtension is the API response for the available extensions.
type AvailableExtension struct {
ID string `json:"id"`
Name string `json:"name"`
DatastoreTypeIDs []string `json:"datastore_type_ids"`
DependencyIDs []string `json:"dependency_ids"`
}
const AvailableExtensionsURI = "/available-extensions"
// AvailableExtensions returns all available extensions.
func (api *API) AvailableExtensions(ctx context.Context) ([]AvailableExtension, error) {
resp, err := api.makeRequest(ctx, http.MethodGet, AvailableExtensionsURI, nil)
if err != nil {
return []AvailableExtension{}, err
}
var result struct {
AvailableExtensions []AvailableExtension `json:"available-extensions"`
}
err = json.Unmarshal(resp, &result)
if err != nil {
return []AvailableExtension{}, fmt.Errorf("Error during Unmarshal, %w", err)
}
return result.AvailableExtensions, nil
}
// AvailableExtension returns an available extension based on the ID.
func (api *API) AvailableExtension(ctx context.Context, availableExtensionID string) (AvailableExtension, error) {
uri := fmt.Sprintf("%s/%s", AvailableExtensionsURI, availableExtensionID)
resp, err := api.makeRequest(ctx, http.MethodGet, uri, nil)
if err != nil {
return AvailableExtension{}, err
}
var result struct {
AvailableExtension AvailableExtension `json:"available-extension"`
}
err = json.Unmarshal(resp, &result)
if err != nil {
return AvailableExtension{}, fmt.Errorf("Error during Unmarshal, %w", err)
}
return result.AvailableExtension, nil
}