-
Notifications
You must be signed in to change notification settings - Fork 2
/
datastore_type.go
55 lines (45 loc) · 1.36 KB
/
datastore_type.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
package dbaas
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
// DatastoreType is the API response for the datastore types.
type DatastoreType struct {
ID string `json:"id"`
Engine string `json:"engine"`
Version string `json:"version"`
}
const DatastoreTypesURI = "/datastore-types"
// DatastoreTypes returns all datastore types.
func (api *API) DatastoreTypes(ctx context.Context) ([]DatastoreType, error) {
resp, err := api.makeRequest(ctx, http.MethodGet, DatastoreTypesURI, nil)
if err != nil {
return []DatastoreType{}, err
}
var result struct {
DatastoreTypes []DatastoreType `json:"datastore-types"`
}
err = json.Unmarshal(resp, &result)
if err != nil {
return []DatastoreType{}, fmt.Errorf("Error during Unmarshal, %w", err)
}
return result.DatastoreTypes, nil
}
// DatastoreType returns a datastore type based on the ID.
func (api *API) DatastoreType(ctx context.Context, datastoreTypeID string) (DatastoreType, error) {
uri := fmt.Sprintf("%s/%s", DatastoreTypesURI, datastoreTypeID)
resp, err := api.makeRequest(ctx, http.MethodGet, uri, nil)
if err != nil {
return DatastoreType{}, err
}
var result struct {
DatastoreType DatastoreType `json:"datastore-type"`
}
err = json.Unmarshal(resp, &result)
if err != nil {
return DatastoreType{}, fmt.Errorf("Error during Unmarshal, %w", err)
}
return result.DatastoreType, nil
}