-
Notifications
You must be signed in to change notification settings - Fork 26
/
charge.go
36 lines (30 loc) · 922 Bytes
/
charge.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
package civogo
import (
"bytes"
"encoding/json"
"fmt"
"time"
)
// Charge represents a Civo resource with number of hours within the specified billing period
type Charge struct {
Code string `json:"code"`
Label string `json:"label"`
From time.Time `json:"from"`
To time.Time `json:"to"`
NumHours int `json:"num_hours"`
SizeGigabytes int `json:"size_gb"`
}
// ListCharges returns all charges for the calling API account
func (c *Client) ListCharges(from, to time.Time) ([]Charge, error) {
url := "/v2/charges"
url = url + fmt.Sprintf("?from=%s&to=%s", from.Format(time.RFC3339), to.Format(time.RFC3339))
resp, err := c.SendGetRequest(url)
if err != nil {
return nil, decodeError(err)
}
charges := make([]Charge, 0)
if err := json.NewDecoder(bytes.NewReader(resp)).Decode(&charges); err != nil {
return nil, err
}
return charges, nil
}