/
pricing.go
139 lines (118 loc) · 3.66 KB
/
pricing.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package hcloud
import (
"context"
"github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
)
// Pricing specifies pricing information for various resources.
type Pricing struct {
Image ImagePricing
FloatingIP FloatingIPPricing
FloatingIPs []FloatingIPTypePricing
PrimaryIPs []PrimaryIPPricing
Traffic TrafficPricing
ServerBackup ServerBackupPricing
ServerTypes []ServerTypePricing
LoadBalancerTypes []LoadBalancerTypePricing
Volume VolumePricing
}
// Price represents a price. Net amount, gross amount, as well as VAT rate are
// specified as strings and it is the user's responsibility to convert them to
// appropriate types for calculations.
type Price struct {
Currency string
VATRate string
Net string
Gross string
}
// PrimaryIPPrice represents a price. Net amount and gross amount are
// specified as strings and it is the user's responsibility to convert them to
// appropriate types for calculations.
type PrimaryIPPrice struct {
Net string
Gross string
}
// ImagePricing provides pricing information for imaegs.
type ImagePricing struct {
PerGBMonth Price
}
// FloatingIPPricing provides pricing information for Floating IPs.
type FloatingIPPricing struct {
Monthly Price
}
// FloatingIPTypePricing provides pricing information for Floating IPs per Type.
type FloatingIPTypePricing struct {
Type FloatingIPType
Pricings []FloatingIPTypeLocationPricing
}
// PrimaryIPTypePricing defines the schema of pricing information for a primary IP
// type at a datacenter.
type PrimaryIPTypePricing struct {
Datacenter string // Deprecated: the API does not return pricing for the individual DCs anymore
Location string
Hourly PrimaryIPPrice
Monthly PrimaryIPPrice
}
// PrimaryIPTypePricing provides pricing information for PrimaryIPs.
type PrimaryIPPricing struct {
Type string
Pricings []PrimaryIPTypePricing
}
// FloatingIPTypeLocationPricing provides pricing information for a Floating IP type
// at a location.
type FloatingIPTypeLocationPricing struct {
Location *Location
Monthly Price
}
// TrafficPricing provides pricing information for traffic.
type TrafficPricing struct {
PerTB Price
}
// VolumePricing provides pricing information for a Volume.
type VolumePricing struct {
PerGBMonthly Price
}
// ServerBackupPricing provides pricing information for server backups.
type ServerBackupPricing struct {
Percentage string
}
// ServerTypePricing provides pricing information for a server type.
type ServerTypePricing struct {
ServerType *ServerType
Pricings []ServerTypeLocationPricing
}
// ServerTypeLocationPricing provides pricing information for a server type
// at a location.
type ServerTypeLocationPricing struct {
Location *Location
Hourly Price
Monthly Price
}
// LoadBalancerTypePricing provides pricing information for a Load Balancer type.
type LoadBalancerTypePricing struct {
LoadBalancerType *LoadBalancerType
Pricings []LoadBalancerTypeLocationPricing
}
// LoadBalancerTypeLocationPricing provides pricing information for a Load Balancer type
// at a location.
type LoadBalancerTypeLocationPricing struct {
Location *Location
Hourly Price
Monthly Price
}
// PricingClient is a client for the pricing API.
type PricingClient struct {
client *Client
}
// Get retrieves pricing information.
func (c *PricingClient) Get(ctx context.Context) (Pricing, *Response, error) {
req, err := c.client.NewRequest(ctx, "GET", "/pricing", nil)
if err != nil {
return Pricing{}, nil, err
}
var body schema.PricingGetResponse
resp, err := c.client.Do(req, &body)
if err != nil {
return Pricing{}, nil, err
}
return PricingFromSchema(body.Pricing), resp, nil
}