Documentation ¶
Index ¶
- Constants
- Variables
- func BoolPtr(v bool) *bool
- func BoolSlicePtr(src []bool) []*bool
- func BytesPtr(v []byte) *[]byte
- func BytesSlicePtr(src [][]byte) []*[]byte
- func DurationPtr(v time.Duration) *time.Duration
- func Float32Ptr(v float32) *float32
- func Float32SlicePtr(src []float32) []*float32
- func Float64Ptr(v float64) *float64
- func Float64SlicePtr(src []float64) []*float64
- func GetCacheDirectory() string
- func GetConfigPath() string
- func IPPtr(v net.IP) *net.IP
- func Int32Ptr(v int32) *int32
- func Int32SlicePtr(src []int32) []*int32
- func Int64Ptr(v int64) *int64
- func Int64SlicePtr(src []int64) []*int64
- func MigrateLegacyConfig() (bool, error)
- func StringPtr(v string) *string
- func StringSlicePtr(src []string) []*string
- func StringsPtr(v []string) *[]string
- func StringsSlicePtr(src [][]string) []*[]string
- func Uint32Ptr(v uint32) *uint32
- func Uint32SlicePtr(src []uint32) []*uint32
- func Uint64Ptr(v uint64) *uint64
- func Uint64SlicePtr(src []uint64) []*uint64
- type Client
- func (c *Client) Do(req *ScalewayRequest, res interface{}, opts ...RequestOption) (err error)
- func (c *Client) GetDefaultOrganizationID() (organizationID string, exists bool)
- func (c *Client) GetDefaultPageSize() (pageSize uint32, exists bool)
- func (c *Client) GetDefaultRegion() (region Region, exists bool)
- func (c *Client) GetDefaultZone() (zone Zone, exists bool)
- type ClientOption
- func WithAPIURL(apiURL string) ClientOption
- func WithAuth(accessKey, secretKey string) ClientOption
- func WithDefaultOrganizationID(organizationID string) ClientOption
- func WithDefaultPageSize(pageSize uint32) ClientOption
- func WithDefaultRegion(region Region) ClientOption
- func WithDefaultZone(zone Zone) ClientOption
- func WithEnv() ClientOption
- func WithHTTPClient(httpClient httpClient) ClientOption
- func WithInsecure() ClientOption
- func WithProfile(p *Profile) ClientOption
- func WithUserAgent(ua string) ClientOption
- func WithoutAuth() ClientOption
- type Config
- type ConfigFileNotFoundError
- type Duration
- type File
- type IPNet
- type InvalidArgumentsError
- type InvalidArgumentsErrorDetail
- type InvalidClientOptionError
- type InvalidRequestError
- type Money
- type OutOfStockError
- type PermissionsDeniedError
- type Profile
- type QuotasExceededError
- type QuotasExceededErrorDetail
- type Region
- type RequestOption
- type ResourceExpiredError
- type ResourceNotFoundError
- type ResponseError
- type ScalewayRequest
- type SdkError
- type ServiceInfo
- type Size
- type TimeSeries
- type TimeSeriesPoint
- type TransientStateError
- type Zone
Constants ¶
const ( B Size = 1 KB = 1000 * B MB = 1000 * KB GB = 1000 * MB TB = 1000 * GB PB = 1000 * TB )
const ( // ZoneFrPar1 represents the fr-par-1 zone ZoneFrPar1 = Zone("fr-par-1") // ZoneFrPar2 represents the fr-par-2 zone ZoneFrPar2 = Zone("fr-par-2") // ZoneNlAms1 represents the nl-ams-1 zone ZoneNlAms1 = Zone("nl-ams-1") )
const ( // RegionFrPar represents the fr-par region RegionFrPar = Region("fr-par") // RegionNlAms represents the nl-ams region RegionNlAms = Region("nl-ams") )
Variables ¶
var ( // AllRegions is an array that list all regions AllRegions = []Region{ RegionFrPar, RegionNlAms, } )
var ( // AllZones is an array that list all zones AllZones = []Zone{ ZoneFrPar1, ZoneFrPar2, ZoneNlAms1, } )
var ( // ErrNoHomeDir errors when no user directory is found ErrNoHomeDir = errors.New("user home directory not found") )
Functions ¶
func BoolSlicePtr ¶
BoolSlicePtr converts a slice of bool values into a slice of bool pointers
func BytesSlicePtr ¶
BytesSlicePtr converts a slice of []byte values into a slice of []byte pointers
func DurationPtr ¶
DurationPtr returns a pointer to the Duration value passed in.
func Float32Ptr ¶
Float32Ptr returns a pointer to the float32 value passed in.
func Float32SlicePtr ¶
Float32SlicePtr converts a slice of float32 values into a slice of float32 pointers
func Float64Ptr ¶
Float64Ptr returns a pointer to the float64 value passed in.
func Float64SlicePtr ¶
Float64SlicePtr converts a slice of float64 values into a slice of float64 pointers
func GetCacheDirectory ¶
func GetCacheDirectory() string
GetCacheDirectory returns the default cache directory. Cache directory is based on the following priority order: - $SCW_CACHE_DIR - $XDG_CACHE_HOME/scw - $HOME/.cache/scw - $USERPROFILE/.cache/scw
func GetConfigPath ¶
func GetConfigPath() string
GetConfigPath returns the default path. Default path is based on the following priority order: - $SCW_CONFIG_PATH - $XDG_CONFIG_HOME/scw/config.yaml - $HOME/.config/scw/config.yaml - $USERPROFILE/.config/scw/config.yaml
func Int32SlicePtr ¶
Int32SlicePtr converts a slice of int32 values into a slice of int32 pointers
func Int64SlicePtr ¶
Int64SlicePtr converts a slice of int64 values into a slice of int64 pointers
func MigrateLegacyConfig ¶
MigrateLegacyConfig will migrate the legacy config to the V2 when none exist yet. Returns a boolean set to true when the migration happened. TODO: get accesskey from account?
func StringSlicePtr ¶
StringSlicePtr converts a slice of string values into a slice of string pointers
func StringsPtr ¶
StringsPtr returns a pointer to the []string value passed in.
func StringsSlicePtr ¶
StringsSlicePtr converts a slice of []string values into a slice of []string pointers
func Uint32SlicePtr ¶
Uint32SlicePtr converts a slice of uint32 values into a slice of uint32 pointers
func Uint64SlicePtr ¶
Uint64SlicePtr converts a slice of uint64 values into a slice of uint64 pointers
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Scaleway client which performs API requests.
This client should be passed in the `NewApi` functions whenever an API instance is created. Creating a Client is done with the `NewClient` function.
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
NewClient instantiate a new Client object.
Zero or more ClientOption object can be passed as a parameter. These options will then be applied to the client.
func (*Client) Do ¶
func (c *Client) Do(req *ScalewayRequest, res interface{}, opts ...RequestOption) (err error)
Do performs HTTP request(s) based on the ScalewayRequest object. RequestOptions are applied prior to doing the request.
func (*Client) GetDefaultOrganizationID ¶
GetDefaultOrganizationID returns the default organization ID of the client. This value can be set in the client option WithDefaultOrganizationID(). Be aware this value can be empty.
func (*Client) GetDefaultPageSize ¶
GetDefaultPageSize returns the default page size of the client. This value can be set in the client option WithDefaultPageSize(). Be aware this value can be empty.
func (*Client) GetDefaultRegion ¶
GetDefaultRegion returns the default region of the client. This value can be set in the client option WithDefaultRegion(). Be aware this value can be empty.
func (*Client) GetDefaultZone ¶
GetDefaultZone returns the default zone of the client. This value can be set in the client option WithDefaultZone(). Be aware this value can be empty.
type ClientOption ¶
type ClientOption func(*settings)
ClientOption is a function which applies options to a settings object.
func WithAPIURL ¶
func WithAPIURL(apiURL string) ClientOption
WithAPIURL client option overrides the API URL of the Scaleway API to the given URL.
func WithAuth ¶
func WithAuth(accessKey, secretKey string) ClientOption
WithAuth client option sets the client access key and secret key.
func WithDefaultOrganizationID ¶
func WithDefaultOrganizationID(organizationID string) ClientOption
WithDefaultOrganizationID client option sets the client default organization ID.
It will be used as the default value of the organization_id field in all requests made with this client.
func WithDefaultPageSize ¶
func WithDefaultPageSize(pageSize uint32) ClientOption
WithDefaultPageSize client option overrides the default page size of the SDK.
It will be used as the default value of the page_size field in all requests made with this client.
func WithDefaultRegion ¶
func WithDefaultRegion(region Region) ClientOption
WithDefaultRegion client option sets the client default region.
It will be used as the default value of the region field in all requests made with this client.
func WithDefaultZone ¶
func WithDefaultZone(zone Zone) ClientOption
WithDefaultZone client option sets the client default zone.
It will be used as the default value of the zone field in all requests made with this client.
func WithEnv ¶
func WithEnv() ClientOption
WithProfile client option configures a client from the environment variables.
func WithHTTPClient ¶
func WithHTTPClient(httpClient httpClient) ClientOption
WithHTTPClient client option allows passing a custom http.Client which will be used for all requests.
func WithInsecure ¶
func WithInsecure() ClientOption
WithInsecure client option enables insecure transport on the client.
func WithProfile ¶
func WithProfile(p *Profile) ClientOption
WithProfile client option configures a client from the given profile.
func WithUserAgent ¶
func WithUserAgent(ua string) ClientOption
WithUserAgent client option append a user agent to the default user agent of the SDK.
func WithoutAuth ¶
func WithoutAuth() ClientOption
WithoutAuth client option sets the client token to an empty token.
type Config ¶
type Config struct { Profile `yaml:",inline"` ActiveProfile *string `yaml:"active_profile,omitempty"` SendTelemetry bool `yaml:"send_telemetry,omitempty"` Profiles map[string]*Profile `yaml:"profiles,omitempty"` }
func LoadConfig ¶
LoadConfig read the config from the default path.
func LoadConfigFromPath ¶
LoadConfigFromPath read the config from the given path.
func MustLoadConfig ¶
func MustLoadConfig() *Config
MustLoadConfig is like LoadConfig but panic instead of returning an error.
func (*Config) GetActiveProfile ¶
GetActiveProfile returns the active profile of the config based on the following order: env SCW_PROFILE > config active_profile > config root profile
func (*Config) GetProfile ¶
GetProfile returns the profile corresponding to the given profile name.
func (*Config) HumanConfig ¶
HumanConfig will generate a config file with documented arguments.
func (*Config) Save ¶
SaveTo will save the config to the default config path. This action will overwrite the previous file when it exists.
type ConfigFileNotFoundError ¶
type ConfigFileNotFoundError struct {
// contains filtered or unexported fields
}
ConfigFileNotFound indicates that the config file could not be found
func (ConfigFileNotFoundError) Error ¶
func (e ConfigFileNotFoundError) Error() string
func (ConfigFileNotFoundError) IsScwSdkError ¶
func (e ConfigFileNotFoundError) IsScwSdkError()
ConfigFileNotFoundError implements the SdkError interface
type Duration ¶
Duration represents a signed, fixed-length span of time represented as a count of seconds and fractions of seconds at nanosecond resolution. It is independent of any calendar and concepts like "day" or "month". It is related to Timestamp in that the difference between two Timestamp values is a Duration and it can be added or subtracted from a Timestamp. Range is approximately +-10,000 years.
func (Duration) MarshalJSON ¶
func (*Duration) ToTimeDuration ¶
func (*Duration) UnmarshalJSON ¶
type File ¶
type File struct { // Name of the file Name string `json:"name"` // ContentType used in the HTTP header `Content-Type` ContentType string `json:"content_type"` // Content of the file Content io.Reader `json:"content"` }
File is the structure used to receive / send a file from / to the API
func (*File) UnmarshalJSON ¶
type IPNet ¶
IPNet inherits net.IPNet and represents an IP network.
func (IPNet) MarshalJSON ¶
func (*IPNet) UnmarshalJSON ¶
type InvalidArgumentsError ¶
type InvalidArgumentsError struct { Details []InvalidArgumentsErrorDetail `json:"details"` RawBody json.RawMessage `json:"-"` }
func (*InvalidArgumentsError) Error ¶
func (e *InvalidArgumentsError) Error() string
func (*InvalidArgumentsError) GetRawBody ¶
func (e *InvalidArgumentsError) GetRawBody() json.RawMessage
func (*InvalidArgumentsError) IsScwSdkError ¶
func (e *InvalidArgumentsError) IsScwSdkError()
IsScwSdkError implements the SdkError interface
type InvalidClientOptionError ¶
type InvalidClientOptionError struct {
// contains filtered or unexported fields
}
InvalidClientOptionError indicates that at least one of client data has been badly provided for the client creation.
func NewInvalidClientOptionError ¶
func NewInvalidClientOptionError(format string, a ...interface{}) *InvalidClientOptionError
func (InvalidClientOptionError) Error ¶
func (e InvalidClientOptionError) Error() string
func (InvalidClientOptionError) IsScwSdkError ¶
func (e InvalidClientOptionError) IsScwSdkError()
IsScwSdkError implements the SdkError interface
type InvalidRequestError ¶
type InvalidRequestError struct { Message string `json:"message"` Fields map[string][]string `json:"fields"` Resource string `json:"resource"` RawBody json.RawMessage `json:"-"` }
InvalidRequestError is only returned by the instance API. Warning: this is not a standard error.
func (*InvalidRequestError) ToInvalidArgumentsError ¶
func (e *InvalidRequestError) ToInvalidArgumentsError() SdkError
ToSdkError returns a standard error InvalidArgumentsError or nil Fields is nil.
func (*InvalidRequestError) ToQuotasExceededError ¶
func (e *InvalidRequestError) ToQuotasExceededError() SdkError
type Money ¶
type Money struct { // CurrencyCode is the 3-letter currency code defined in ISO 4217. CurrencyCode string `json:"currency_code"` // Units is the whole units of the amount. // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. Units int64 `json:"units"` // Nanos is the number of nano (10^-9) units of the amount. // The value must be between -999,999,999 and +999,999,999 inclusive. // If `units` is positive, `nanos` must be positive or zero. // If `units` is zero, `nanos` can be positive, zero, or negative. // If `units` is negative, `nanos` must be negative or zero. // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. Nanos int32 `json:"nanos"` }
Money represents an amount of money with its currency type.
func NewMoneyFromFloat ¶
NewMoneyFromFloat converts a float with currency to a Money.
value: The float value. currencyCode: The 3-letter currency code defined in ISO 4217. precision: The number of digits after the decimal point used to parse the nanos part of the value.
Examples: - (value = 1.3333, precision = 2) => Money{Units = 1, Nanos = 330000000} - (value = 1.123456789, precision = 9) => Money{Units = 1, Nanos = 123456789}
type OutOfStockError ¶
type OutOfStockError struct { Resource string `json:"resource"` RawBody json.RawMessage `json:"-"` }
func (*OutOfStockError) Error ¶
func (e *OutOfStockError) Error() string
func (*OutOfStockError) GetRawBody ¶
func (e *OutOfStockError) GetRawBody() json.RawMessage
func (*OutOfStockError) IsScwSdkError ¶
func (e *OutOfStockError) IsScwSdkError()
IsScwSdkError implements the SdkError interface
type PermissionsDeniedError ¶
type PermissionsDeniedError struct { Details []struct { Resource string `json:"resource"` Action string `json:"action"` } `json:"details"` RawBody json.RawMessage `json:"-"` }
func (*PermissionsDeniedError) Error ¶
func (e *PermissionsDeniedError) Error() string
func (*PermissionsDeniedError) GetRawBody ¶
func (e *PermissionsDeniedError) GetRawBody() json.RawMessage
func (*PermissionsDeniedError) IsScwSdkError ¶
func (e *PermissionsDeniedError) IsScwSdkError()
IsScwSdkError implements the SdkError interface
type Profile ¶
type Profile struct { AccessKey *string `yaml:"access_key,omitempty"` SecretKey *string `yaml:"secret_key,omitempty"` APIURL *string `yaml:"api_url,omitempty"` Insecure *bool `yaml:"insecure,omitempty"` DefaultOrganizationID *string `yaml:"default_organization_id,omitempty"` DefaultRegion *string `yaml:"default_region,omitempty"` DefaultZone *string `yaml:"default_zone,omitempty"` }
func LoadEnvProfile ¶
func LoadEnvProfile() *Profile
func MergeProfiles ¶
MergeProfiles merges profiles in a new one. The last profile has priority.
type QuotasExceededError ¶
type QuotasExceededError struct { Details []QuotasExceededErrorDetail `json:"details"` RawBody json.RawMessage `json:"-"` }
func (*QuotasExceededError) Error ¶
func (e *QuotasExceededError) Error() string
func (*QuotasExceededError) GetRawBody ¶
func (e *QuotasExceededError) GetRawBody() json.RawMessage
func (*QuotasExceededError) IsScwSdkError ¶
func (e *QuotasExceededError) IsScwSdkError()
IsScwSdkError implements the SdkError interface
type Region ¶
type Region string
Region is a geographical location
func ParseRegion ¶
ParseRegion parses a string value into a Region and returns an error if it has a bad format.
func (*Region) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaler interface for a Region. this to call ParseRegion on the string input and return the correct Region object.
type RequestOption ¶
type RequestOption func(*ScalewayRequest)
RequestOption is a function that applies options to a ScalewayRequest.
func WithAllPages ¶
func WithAllPages() RequestOption
WithAllPages aggregate all pages in the response of a List request. Will error when pagination is not supported on the request.
func WithAuthRequest ¶
func WithAuthRequest(accessKey, secretKey string) RequestOption
WithAuthRequest overwrites the client access key and secret key used in the request.
func WithContext ¶
func WithContext(ctx context.Context) RequestOption
WithContext request option sets the context of a ScalewayRequest
type ResourceExpiredError ¶
type ResourceExpiredError struct { Resource string `json:"resource"` ResourceID string `json:"resource_id"` ExpiredSince time.Time `json:"expired_since"` RawBody json.RawMessage `json:"-"` }
ResourceExpiredError implements the SdkError interface
func (ResourceExpiredError) Error ¶
func (r ResourceExpiredError) Error() string
func (ResourceExpiredError) IsScwSdkError ¶
func (r ResourceExpiredError) IsScwSdkError()
type ResourceNotFoundError ¶
type ResourceNotFoundError struct { Resource string `json:"resource"` ResourceID string `json:"resource_id"` RawBody json.RawMessage `json:"-"` }
func (*ResourceNotFoundError) Error ¶
func (e *ResourceNotFoundError) Error() string
func (*ResourceNotFoundError) GetRawBody ¶
func (e *ResourceNotFoundError) GetRawBody() json.RawMessage
func (*ResourceNotFoundError) IsScwSdkError ¶
func (e *ResourceNotFoundError) IsScwSdkError()
IsScwSdkError implements the SdkError interface
type ResponseError ¶
type ResponseError struct { // Message is a human-friendly error message Message string `json:"message"` // Type is a string code that defines the kind of error. This field is only used by instance API Type string `json:"type,omitempty"` // Resource is a string code that defines the resource concerned by the error. This field is only used by instance API Resource string `json:"resource,omitempty"` // Fields contains detail about validation error. This field is only used by instance API Fields map[string][]string `json:"fields,omitempty"` // StatusCode is the HTTP status code received StatusCode int `json:"-"` // Status is the HTTP status received Status string `json:"-"` RawBody json.RawMessage `json:"-"` }
ResponseError is an error type for the Scaleway API
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
func (*ResponseError) GetRawBody ¶
func (e *ResponseError) GetRawBody() json.RawMessage
func (*ResponseError) IsScwSdkError ¶
func (e *ResponseError) IsScwSdkError()
IsScwSdkError implement SdkError interface
func (*ResponseError) UnmarshalJSON ¶
func (e *ResponseError) UnmarshalJSON(b []byte) error
type ScalewayRequest ¶
type ScalewayRequest struct { Method string Path string Headers http.Header Query url.Values Body io.Reader // contains filtered or unexported fields }
ScalewayRequest contains all the contents related to performing a request on the Scaleway API.
func (*ScalewayRequest) SetBody ¶
func (req *ScalewayRequest) SetBody(body interface{}) error
SetBody json marshal the given body and write the json content type to the request. It also catches when body is a file.
type SdkError ¶
type SdkError interface { Error() string IsScwSdkError() }
SdkError is a base interface for all Scaleway SDK errors.
type ServiceInfo ¶
type ServiceInfo struct { // Name is the name of the API Name string `json:"name"` // Description is a human readable description for the API Description string `json:"description"` // Version is the version of the API Version string `json:"version"` // DocumentationURL is the a web url where the documentation of the API can be found DocumentationURL *string `json:"documentation_url"` }
ServiceInfo contains API metadata These metadata are only here for debugging. Do not rely on these values
type TimeSeries ¶
type TimeSeries struct { // Name of the metric. Name string `json:"name"` // Points contains all the points that composed the series. Points []*TimeSeriesPoint `json:"points"` // Metadata contains some string metadata related to a metric. Metadata map[string]string `json:"metadata"` }
TimeSeries represents a time series that could be used for graph purposes.
type TimeSeriesPoint ¶
TimeSeriesPoint represents a point of a time series.
func (TimeSeriesPoint) MarshalJSON ¶
func (tsp TimeSeriesPoint) MarshalJSON() ([]byte, error)
func (*TimeSeriesPoint) UnmarshalJSON ¶
func (tsp *TimeSeriesPoint) UnmarshalJSON(b []byte) error
type TransientStateError ¶
type TransientStateError struct { Resource string `json:"resource"` ResourceID string `json:"resource_id"` CurrentState string `json:"current_state"` RawBody json.RawMessage `json:"-"` }
func (*TransientStateError) Error ¶
func (e *TransientStateError) Error() string
func (*TransientStateError) GetRawBody ¶
func (e *TransientStateError) GetRawBody() json.RawMessage
func (*TransientStateError) IsScwSdkError ¶
func (e *TransientStateError) IsScwSdkError()
IsScwSdkError implements the SdkError interface
type Zone ¶
type Zone string
Zone is an availability zone
func ParseZone ¶
ParseZone parses a string value into a Zone and returns an error if it has a bad format.
func (*Zone) Region ¶
Region returns the parent Region for the Zone. Manipulates the string directly to allow unlisted zones formatted as xx-yyy-z.
func (*Zone) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaler interface for a Zone. this to call ParseZone on the string input and return the correct Zone object.