/
api.go
44 lines (34 loc) · 894 Bytes
/
api.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
package govultr
import (
"context"
"net/http"
)
// APIService is the interface to interact with the API endpoint on the Vultr API
// Link: https://www.vultr.com/api/#auth
type APIService interface {
GetInfo(ctx context.Context) (*API, error)
}
// APIServiceHandler handles interaction with the API methods for the Vultr API
type APIServiceHandler struct {
client *Client
}
// API represents Vultr API information
type API struct {
ACL []string `json:"acls"`
Email string `json:"email"`
Name string `json:"name"`
}
// GetInfo Vultr API auth information
func (a *APIServiceHandler) GetInfo(ctx context.Context) (*API, error) {
uri := "/v1/auth/info"
req, err := a.client.NewRequest(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, err
}
api := new(API)
err = a.client.DoWithContext(ctx, req, api)
if err != nil {
return nil, err
}
return api, nil
}