network_transfer_prices.go raw

   1  package linodego
   2  
   3  import (
   4  	"context"
   5  )
   6  
   7  // NetworkTransferPrice represents a single valid network transfer price.
   8  type NetworkTransferPrice struct {
   9  	baseType[NetworkTransferTypePrice, NetworkTransferTypeRegionPrice]
  10  }
  11  
  12  // NetworkTransferTypePrice represents the base hourly and monthly prices
  13  // for a network transfer price entry.
  14  type NetworkTransferTypePrice struct {
  15  	baseTypePrice
  16  }
  17  
  18  // NetworkTransferTypeRegionPrice represents the regional hourly and monthly prices
  19  // for a network transfer price entry.
  20  type NetworkTransferTypeRegionPrice struct {
  21  	baseTypeRegionPrice
  22  }
  23  
  24  // ListNetworkTransferPrices lists network transfer prices. This endpoint is cached by default.
  25  func (c *Client) ListNetworkTransferPrices(ctx context.Context, opts *ListOptions) ([]NetworkTransferPrice, error) {
  26  	e := "network-transfer/prices"
  27  
  28  	endpoint, err := generateListCacheURL(e, opts)
  29  	if err != nil {
  30  		return nil, err
  31  	}
  32  
  33  	if result := c.getCachedResponse(endpoint); result != nil {
  34  		return result.([]NetworkTransferPrice), nil
  35  	}
  36  
  37  	response, err := getPaginatedResults[NetworkTransferPrice](ctx, c, e, opts)
  38  	if err != nil {
  39  		return nil, err
  40  	}
  41  
  42  	c.addCachedResponse(endpoint, response, &cacheExpiryTime)
  43  
  44  	return response, nil
  45  }
  46