File: regions_availability.go

package info (click to toggle)
golang-github-linode-linodego 1.47.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 10,032 kB
  • sloc: makefile: 95; sh: 52; python: 24
file content (54 lines) | stat: -rw-r--r-- 1,405 bytes parent folder | download
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
}