shared

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2023 License: Apache-2.0 Imports: 11 Imported by: 9

Documentation

Index

Constants

View Source
const (
	IonosUsernameEnvVar   = "IONOS_USERNAME"
	IonosPasswordEnvVar   = "IONOS_PASSWORD"
	IonosTokenEnvVar      = "IONOS_TOKEN"
	IonosApiUrlEnvVar     = "IONOS_API_URL"
	IonosPinnedCertEnvVar = "IONOS_PINNED_CERT"
	IonosLogLevelEnvVar   = "IONOS_LOG_LEVEL"
	DefaultIonosServerUrl = "https://api.ionos.com/"
)

Variables

View Source
var (
	// ContextOAuth2 takes an oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKeys takes a string apikey as authentication for the request
	ContextAPIKeys = contextKey("apiKeys")

	// ContextHttpSignatureAuth takes HttpSignatureAuth as authentication for the request.
	ContextHttpSignatureAuth = contextKey("httpsignature")

	// ContextServerIndex uses a server configuration from the index.
	ContextServerIndex = contextKey("serverIndex")

	// ContextOperationServerIndices uses a server configuration from the index mapping.
	ContextOperationServerIndices = contextKey("serverOperationIndices")

	// ContextServerVariables overrides a server configuration variables.
	ContextServerVariables = contextKey("serverVariables")

	// ContextOperationServerVariables overrides a server configuration variables using operation specific values.
	ContextOperationServerVariables = contextKey("serverOperationVariables")
)
View Source
var DefaultIonosBasePath = ""
View Source
var LogLevelMap = map[string]LogLevel{
	"off":   Off,
	"debug": Debug,
	"trace": Trace,
}

Functions

func All added in v0.1.1

func All[T any](xs []T, f func(T) bool) bool

All returns true if all elements of a slice satisfy a given predicate function, and false otherwise.

func Any added in v0.1.1

func Any[T any](xs []T, f func(T) bool) bool

Any returns true if at least one element of a slice satisfies a given predicate function, and false otherwise.

func ApplyAndAggregateErrors added in v0.1.1

func ApplyAndAggregateErrors[T any](xs []T, f func(T) error) error

ApplyAndAggregateErrors applies the provided function for each element of the slice If the function returns an error, it accumulates the error and continues execution After all elements are processed, it returns the aggregated errors if any

func ApplyOrFail added in v0.1.1

func ApplyOrFail[T any](xs []T, f func(T) error) error

ApplyOrFail tries applying the provided function for each element of the slice If the function returns an error, we break execution and return the error

func Filter added in v0.1.1

func Filter[T any](xs []T, f func(T) bool) []T

Filter applies a function to each element of a slice, returning a new slice with only the elements for which the function returns true.

func Fold added in v0.1.1

func Fold[T any, Acc any](xs []T, f func(Acc, T) Acc, acc Acc) Acc

Fold (aka Reduce) accumulates the result of f into acc and returns acc by applying f over each element in the slice

func IsNil

func IsNil(i interface{}) bool

IsNil checks if an input is nil

func Map added in v0.1.1

func Map[T comparable, K any](s []T, f func(T) K) []K

Map applies a function to each element of a slice and returns the modified slice without considering the index of each element.

func MapIdx added in v0.1.1

func MapIdx[V comparable, R any](s []V, f func(int, V) R) []R

MapIdx applies a function to each element and index of a slice, returning the modified slice with consideration of the index.

func NewSdkLogger

func NewSdkLogger()

func SetBasePath

func SetBasePath(basePath string)

func SliceToValueDefault

func SliceToValueDefault[T any](ptrSlice *[]T) []T

func Strlen

func Strlen(s string) int

func ToPtr

func ToPtr[T any](v T) *T

ToPtr - returns a pointer to the given value.

func ToValue

func ToValue[T any](ptr *T) T

ToValue - returns the value of the bool pointer passed in

func ToValueDefault

func ToValueDefault[T any](ptr *T) T

ToValueDefault - returns the value of the pointer passed in, or the default type value if the pointer is nil

Types

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the OpenAPI operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// RequestTime is the time duration from the moment the APIClient sends
	// the HTTP request to the moment it receives an HTTP response.
	RequestTime time.Duration `json:"duration,omitempty"`
	// Method is the HTTP method used for the request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the response body (which may be nil or empty).
	// This is provided here as the raw response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

APIResponse stores the API response returned by the server.

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

NewAPIResponse returns a new APIResonse object.

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

NewAPIResponseWithError returns a new APIResponse object with the provided error message.

func (*APIResponse) HttpNotFound

func (resp *APIResponse) HttpNotFound() bool

HttpNotFound - returns true if a 404 status code was returned returns false for nil APIResponse values

func (*APIResponse) LogInfo

func (resp *APIResponse) LogInfo()

LogInfo - logs APIResponse values like RequestTime, Operation and StatusCode does not print anything for nil APIResponse values

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type Configuration

type Configuration struct {
	Host               string            `json:"host,omitempty"`
	Scheme             string            `json:"scheme,omitempty"`
	DefaultHeader      map[string]string `json:"defaultHeader,omitempty"`
	DefaultQueryParams url.Values        `json:"defaultQueryParams,omitempty"`
	UserAgent          string            `json:"userAgent,omitempty"`
	Servers            ServerConfigurations
	OperationServers   map[string]ServerConfigurations
	HTTPClient         *http.Client
	Username           string        `json:"username,omitempty"`
	Password           string        `json:"password,omitempty"`
	Token              string        `json:"token,omitempty"`
	MaxRetries         int           `json:"maxRetries,omitempty"`
	WaitTime           time.Duration `json:"waitTime,omitempty"`
	MaxWaitTime        time.Duration `json:"maxWaitTime,omitempty"`
}

shared.Configuration stores the configuration of the API client

func NewConfiguration

func NewConfiguration(username, password, token, hostUrl string) *Configuration

NewConfiguration returns a new shared.Configuration object

func NewConfigurationFromEnv

func NewConfigurationFromEnv() *Configuration

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

AddDefaultHeader adds a new HTTP header to the default header in the request

func (*Configuration) AddDefaultQueryParam

func (c *Configuration) AddDefaultQueryParam(key string, value string)

func (*Configuration) ServerURL

func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error)

ServerURL returns URL based on server settings

func (*Configuration) ServerURLWithContext

func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error)

ServerURLWithContext returns a new server URL given an endpoint

type GenericOpenAPIError

type GenericOpenAPIError struct {
	// contains filtered or unexported fields
}

GenericOpenAPIError Provides access to the body, error and model on returned errors.

func NewGenericOpenAPIError

func NewGenericOpenAPIError(message string, body []byte, model interface{}, statusCode int) *GenericOpenAPIError

NewGenericOpenAPIError - constructor for GenericOpenAPIError

func (GenericOpenAPIError) Body

func (e GenericOpenAPIError) Body() []byte

Body returns the raw bytes of the response

func (GenericOpenAPIError) Error

func (e GenericOpenAPIError) Error() string

Error returns non-empty string if there was an error.

func (GenericOpenAPIError) Model

func (e GenericOpenAPIError) Model() interface{}

Model returns the unpacked model of the error

func (*GenericOpenAPIError) SetBody

func (e *GenericOpenAPIError) SetBody(body []byte)

SetBody sets the raw body of the error

func (*GenericOpenAPIError) SetError

func (e *GenericOpenAPIError) SetError(error string)

SetError sets the error string

func (*GenericOpenAPIError) SetModel

func (e *GenericOpenAPIError) SetModel(model interface{})

SetModel sets the model of the error

func (*GenericOpenAPIError) SetStatusCode

func (e *GenericOpenAPIError) SetStatusCode(statusCode int)

SetStatusCode sets the status code of the error

func (GenericOpenAPIError) StatusCode

func (e GenericOpenAPIError) StatusCode() int

StatusCode returns the status code of the error

type LogLevel

type LogLevel uint
const (
	Off LogLevel = 0x100 * iota
	Debug
	// Trace We recommend you only set this field for debugging purposes.
	// Disable it in your production environments because it can log sensitive data.
	// It logs the full request and response without encryption, even for an HTTPS call.
	// Verbose request and response logging can also significantly impact your application's performance.
	Trace
)
var SdkLogLevel LogLevel

func (*LogLevel) Get

func (l *LogLevel) Get() LogLevel

func (*LogLevel) Satisfies

func (l *LogLevel) Satisfies(v LogLevel) bool

Satisfies returns true if this LogLevel is at least high enough for v

type Logger

type Logger interface {
	Printf(format string, args ...interface{})
}
var SdkLogger Logger

type Nullable

type Nullable[T any] struct {
	// contains filtered or unexported fields
}

func (Nullable[T]) Get

func (v Nullable[T]) Get() *T

func (Nullable[T]) IsSet

func (v Nullable[T]) IsSet() bool

func (*Nullable[T]) Set

func (v *Nullable[T]) Set(val *T)

func (*Nullable[T]) Unset

func (v *Nullable[T]) Unset()

type ServerConfiguration

type ServerConfiguration struct {
	URL         string
	Description string
	Variables   map[string]ServerVariable
}

ServerConfiguration stores the information about a server

type ServerConfigurations

type ServerConfigurations []ServerConfiguration

ServerConfigurations stores multiple ServerConfiguration items

func (ServerConfigurations) URL

func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error)

URL formats template on a index using given variables

type ServerVariable

type ServerVariable struct {
	Description  string
	DefaultValue string
	EnumValues   []string
}

ServerVariable stores the information about a server variable

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL