-
Notifications
You must be signed in to change notification settings - Fork 56
/
os.go
57 lines (46 loc) · 1.35 KB
/
os.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
57
package govultr
import (
"context"
"net/http"
"github.com/google/go-querystring/query"
)
// OSService is the interface to interact with the operating system endpoint on the Vultr API
// Link : https://www.vultr.com/api/#tag/os
type OSService interface {
List(ctx context.Context, options *ListOptions) ([]OS, *Meta, *http.Response, error)
}
// OSServiceHandler handles interaction with the operating system methods for the Vultr API
type OSServiceHandler struct {
client *Client
}
// OS represents a Vultr operating system
type OS struct {
ID int `json:"id"`
Name string `json:"name"`
Arch string `json:"arch"`
Family string `json:"family"`
}
type osBase struct {
OS []OS `json:"os"`
Meta *Meta `json:"meta"`
}
var _ OSService = &OSServiceHandler{}
// List retrieves a list of available operating systems.
func (o *OSServiceHandler) List(ctx context.Context, options *ListOptions) ([]OS, *Meta, *http.Response, error) { //nolint:dupl
uri := "/v2/os"
req, err := o.client.NewRequest(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, nil, nil, err
}
newValues, err := query.Values(options)
if err != nil {
return nil, nil, nil, err
}
req.URL.RawQuery = newValues.Encode()
os := new(osBase)
resp, err := o.client.DoWithContext(ctx, req, os)
if err != nil {
return nil, nil, resp, err
}
return os.OS, os.Meta, resp, nil
}