1package govultr 2 3import ( 4 "context" 5 "net/http" 6 7 "github.com/google/go-querystring/query" 8) 9 10// OSService is the interface to interact with the operating system endpoint on the Vultr API 11// Link : https://www.vultr.com/api/#tag/os 12type OSService interface { 13 List(ctx context.Context, options *ListOptions) ([]OS, *Meta, error) 14} 15 16// OSServiceHandler handles interaction with the operating system methods for the Vultr API 17type OSServiceHandler struct { 18 client *Client 19} 20 21// OS represents a Vultr operating system 22type OS struct { 23 ID int `json:"id"` 24 Name string `json:"name"` 25 Arch string `json:"arch"` 26 Family string `json:"family"` 27} 28 29type osBase struct { 30 OS []OS `json:"os"` 31 Meta *Meta `json:"meta"` 32} 33 34var _ OSService = &OSServiceHandler{} 35 36// List retrieves a list of available operating systems. 37func (o *OSServiceHandler) List(ctx context.Context, options *ListOptions) ([]OS, *Meta, error) { 38 uri := "/v2/os" 39 req, err := o.client.NewRequest(ctx, http.MethodGet, uri, nil) 40 if err != nil { 41 return nil, nil, err 42 } 43 44 newValues, err := query.Values(options) 45 if err != nil { 46 return nil, nil, err 47 } 48 req.URL.RawQuery = newValues.Encode() 49 50 os := new(osBase) 51 if err = o.client.DoWithContext(ctx, req, os); err != nil { 52 return nil, nil, err 53 } 54 55 return os.OS, os.Meta, nil 56} 57