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
|
package linodego
import (
"context"
"net/url"
)
// LinodeType represents a linode type object
type LinodeType struct {
ID string `json:"id"`
Disk int `json:"disk"`
Class LinodeTypeClass `json:"class"` // enum: nanode, standard, highmem, dedicated, gpu
Price *LinodePrice `json:"price"`
Label string `json:"label"`
Addons *LinodeAddons `json:"addons"`
RegionPrices []LinodeRegionPrice `json:"region_prices"`
NetworkOut int `json:"network_out"`
Memory int `json:"memory"`
Transfer int `json:"transfer"`
VCPUs int `json:"vcpus"`
GPUs int `json:"gpus"`
Successor string `json:"successor"`
AcceleratedDevices int `json:"accelerated_devices"`
}
// LinodePrice represents a linode type price object
type LinodePrice struct {
Hourly float32 `json:"hourly"`
Monthly float32 `json:"monthly"`
}
// LinodeBackupsAddon represents a linode backups addon object
type LinodeBackupsAddon struct {
Price *LinodePrice `json:"price"`
RegionPrices []LinodeRegionPrice `json:"region_prices"`
}
// LinodeAddons represent the linode addons object
type LinodeAddons struct {
Backups *LinodeBackupsAddon `json:"backups"`
}
// LinodeRegionPrice represents an individual type or addon
// price exception for a region.
type LinodeRegionPrice struct {
ID string `json:"id"`
Hourly float32 `json:"hourly"`
Monthly float32 `json:"monthly"`
}
// LinodeTypeClass constants start with Class and include Linode API Instance Type Classes
type LinodeTypeClass string
// LinodeTypeClass constants are the Instance Type Classes that an Instance Type can be assigned
const (
ClassNanode LinodeTypeClass = "nanode"
ClassStandard LinodeTypeClass = "standard"
ClassHighmem LinodeTypeClass = "highmem"
ClassDedicated LinodeTypeClass = "dedicated"
ClassGPU LinodeTypeClass = "gpu"
)
// ListTypes lists linode types. This endpoint is cached by default.
func (c *Client) ListTypes(ctx context.Context, opts *ListOptions) ([]LinodeType, error) {
e := "linode/types"
endpoint, err := generateListCacheURL(e, opts)
if err != nil {
return nil, err
}
if result := c.getCachedResponse(endpoint); result != nil {
return result.([]LinodeType), nil
}
response, err := getPaginatedResults[LinodeType](ctx, c, e, opts)
if err != nil {
return nil, err
}
c.addCachedResponse(endpoint, response, &cacheExpiryTime)
return response, nil
}
// GetType gets the type with the provided ID. This endpoint is cached by default.
func (c *Client) GetType(ctx context.Context, typeID string) (*LinodeType, error) {
e := formatAPIPath("linode/types/%s", url.PathEscape(typeID))
if result := c.getCachedResponse(e); result != nil {
result := result.(LinodeType)
return &result, nil
}
response, err := doGETRequest[LinodeType](ctx, c, e)
if err != nil {
return nil, err
}
c.addCachedResponse(e, response, &cacheExpiryTime)
return response, nil
}
|