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
|
package govultr
import (
"context"
"net/http"
)
// AccountService is the interface to interact with Accounts endpoint on the Vultr API
// Link : https://www.vultr.com/api/#tag/account
type AccountService interface {
Get(ctx context.Context) (*Account, error)
}
// AccountServiceHandler handles interaction with the account methods for the Vultr API
type AccountServiceHandler struct {
client *Client
}
type accountBase struct {
Account *Account `json:"account"`
}
// Account represents a Vultr account
type Account struct {
Balance float32 `json:"balance"`
PendingCharges float32 `json:"pending_charges"`
LastPaymentDate string `json:"last_payment_date"`
LastPaymentAmount float32 `json:"last_payment_amount"`
Name string `json:"name"`
Email string `json:"email"`
ACL []string `json:"acls"`
}
// Get Vultr account info
func (a *AccountServiceHandler) Get(ctx context.Context) (*Account, error) {
uri := "/v2/account"
req, err := a.client.NewRequest(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, err
}
account := new(accountBase)
if err = a.client.DoWithContext(ctx, req, account); err != nil {
return nil, err
}
return account.Account, nil
}
|