-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathregions_availability.go
54 lines (41 loc) · 1.37 KB
/
regions_availability.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
package linodego
import (
"context"
)
// Region represents a linode region object
type RegionAvailability struct {
Region string `json:"region"`
Plan string `json:"plan"`
Available bool `json:"available"`
}
// ListRegionsAvailability lists Regions. This endpoint is cached by default.
func (c *Client) ListRegionsAvailability(ctx context.Context, opts *ListOptions) ([]RegionAvailability, error) {
e := "regions/availability"
endpoint, err := generateListCacheURL(e, opts)
if err != nil {
return nil, err
}
if result := c.getCachedResponse(endpoint); result != nil {
return result.([]RegionAvailability), nil
}
response, err := getPaginatedResults[RegionAvailability](ctx, c, e, opts)
if err != nil {
return nil, err
}
c.addCachedResponse(endpoint, response, &cacheExpiryTime)
return response, nil
}
// GetRegionAvailability gets the template with the provided ID. This endpoint is cached by default.
func (c *Client) GetRegionAvailability(ctx context.Context, regionID string) (*RegionAvailability, error) {
e := formatAPIPath("regions/%s/availability", regionID)
if result := c.getCachedResponse(e); result != nil {
result := result.(RegionAvailability)
return &result, nil
}
response, err := doGETRequest[RegionAvailability](ctx, c, e)
if err != nil {
return nil, err
}
c.addCachedResponse(e, response, &cacheExpiryTime)
return response, nil
}