Documentation ¶
Index ¶
- Constants
- type Client
- func (c *Client) AddRequestHeaders(request *http.Request) *http.Request
- func (c *Client) CreateRequestURL(location string) string
- func (c *Client) GetTimeout() time.Duration
- func (c *Client) PerformJSONDeleteRequest(url string) error
- func (c *Client) PerformJSONDeleteRequestWithResponseBody(url string) ([]byte, error)
- func (c *Client) PerformJSONGetRequest(url string) ([]byte, error)
- func (c *Client) PerformJSONPatchRequest(url string, requestBody []byte) ([]byte, error)
- func (c *Client) PerformJSONPostRequest(url string, requestBody []byte) ([]byte, error)
- func (c *Client) PerformJSONPutRequest(url string, requestBody []byte) ([]byte, error)
- func (c *Client) PerformJSONPutUploadRequest(url string, requestBody io.Reader) ([]byte, error)
- func (c *Client) PerformRequest(request *http.Request) ([]byte, error)
- func (c *Client) SetTimeout(timeout time.Duration)
- type ClientContext
- func (c *ClientContext) PerformJSONDeleteRequest(ctx context.Context, url string) error
- func (c *ClientContext) PerformJSONDeleteRequestWithResponseBody(ctx context.Context, url string) ([]byte, error)
- func (c *ClientContext) PerformJSONGetRequest(ctx context.Context, url string) ([]byte, error)
- func (c *ClientContext) PerformJSONPatchRequest(ctx context.Context, url string, requestBody []byte) ([]byte, error)
- func (c *ClientContext) PerformJSONPostRequest(ctx context.Context, url string, requestBody []byte) ([]byte, error)
- func (c *ClientContext) PerformJSONPutRequest(ctx context.Context, url string, requestBody []byte) ([]byte, error)
- func (c *ClientContext) PerformJSONPutUploadRequest(ctx context.Context, url string, requestBody io.Reader) ([]byte, error)
- func (c *ClientContext) PerformJSONRequest(ctx context.Context, method, url string, body io.Reader) ([]byte, error)
- type Error
- type ErrorType
Examples ¶
Constants ¶
const ( DefaultAPIVersion = "1.3.6" DefaultAPIBaseURL = "https://api.upcloud.com" // The default timeout (in seconds) DefaultTimeout = 60 EnvDebugAPIBaseURL string = "UPCLOUD_DEBUG_API_BASE_URL" EnvDebugSkipCertificateVerify string = "UPCLOUD_DEBUG_SKIP_CERTIFICATE_VERIFY" )
Constants
const ( ErrorTypeError = iota ErrorTypeProblem )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { UserAgent string // contains filtered or unexported fields }
Client represents an API client
func New ¶
New creates ands returns a new client configured with the specified user and password
Example ¶
client := New(os.Getenv("UPCLOUD_USERNAME"), os.Getenv("UPCLOUD_PASSWORD")) client.SetTimeout(10 * time.Second)
Output:
func NewWithHTTPClient ¶
NewWithHTTPClient creates ands returns a new client configured with the specified user and password and using a supplied `http.Client`.
Example ¶
client := NewWithHTTPClient(os.Getenv("UPCLOUD_USERNAME"), os.Getenv("UPCLOUD_PASSWORD"), &http.Client{ // setup custom HTTP client }) client.SetTimeout(10 * time.Second)
Output:
func (*Client) AddRequestHeaders ¶
Adds common headers to the specified request
func (*Client) CreateRequestURL ¶
CreateRequestURL creates and returns a complete request URL for the specified API location using a newer API version
func (*Client) GetTimeout ¶
GetTimeout returns current timeout
func (*Client) PerformJSONDeleteRequest ¶
PerformJSONDeleteRequest performs a DELETE request to the specified URL and returns eventual errors
func (*Client) PerformJSONDeleteRequestWithResponseBody ¶
PerformJSONDeleteRequestWithResponseBody performs a DELETE request to the specified URL and returns the response body and eventual errors
func (*Client) PerformJSONGetRequest ¶
PerformJSONGetRequest performs a GET request to the specified URL and returns the response body and eventual errors
func (*Client) PerformJSONPatchRequest ¶
PerformJSONPatchRequest performs a PATCH request to the specified URL and returns the response body and eventual errors
func (*Client) PerformJSONPostRequest ¶
PerformJSONPostRequest performs a POST request to the specified URL and returns the response body and eventual errors
func (*Client) PerformJSONPutRequest ¶
PerformJSONPutRequest performs a PUT request to the specified URL and returns the response body and eventual errors
func (*Client) PerformJSONPutUploadRequest ¶
PerformJSONPutUploadRequest performs a PUT request to the specified URL with an io.Reader and returns the response body and eventual errors
func (*Client) PerformRequest ¶
Performs the specified HTTP request and returns the response through handleResponse()
func (*Client) SetTimeout ¶
SetTimeout sets the client timeout to the specified amount of seconds
type ClientContext ¶ added in v4.7.0
type ClientContext struct {
*Client
}
ClientContext represents an API client with context support
func NewWithContext ¶ added in v4.7.0
func NewWithContext(userName, password string) *ClientContext
NewWithContext creates ands returns a new client with context support configured with the specified user and password
func NewWithHTTPClientContext ¶ added in v4.7.0
func NewWithHTTPClientContext(userName string, password string, httpClient *http.Client) *ClientContext
NewWithHTTPClientContext creates ands returns a new client with context support configured with the specified user and password and using a supplied `http.Client`.
func (*ClientContext) PerformJSONDeleteRequest ¶ added in v4.7.0
func (c *ClientContext) PerformJSONDeleteRequest(ctx context.Context, url string) error
PerformJSONDeleteRequest performs a DELETE request to the specified URL and returns eventual errors
func (*ClientContext) PerformJSONDeleteRequestWithResponseBody ¶ added in v4.7.0
func (c *ClientContext) PerformJSONDeleteRequestWithResponseBody(ctx context.Context, url string) ([]byte, error)
PerformJSONDeleteRequestWithResponseBody performs a DELETE request to the specified URL and returns the response body and eventual errors
func (*ClientContext) PerformJSONGetRequest ¶ added in v4.7.0
PerformJSONGetRequest performs a GET request to the specified URL and returns the response body and eventual errors
func (*ClientContext) PerformJSONPatchRequest ¶ added in v4.7.0
func (c *ClientContext) PerformJSONPatchRequest(ctx context.Context, url string, requestBody []byte) ([]byte, error)
PerformJSONPatchRequest performs a PATCH request to the specified URL and returns the response body and eventual errors
func (*ClientContext) PerformJSONPostRequest ¶ added in v4.7.0
func (c *ClientContext) PerformJSONPostRequest(ctx context.Context, url string, requestBody []byte) ([]byte, error)
PerformJSONPostRequest performs a POST request to the specified URL and returns the response body and eventual errors
func (*ClientContext) PerformJSONPutRequest ¶ added in v4.7.0
func (c *ClientContext) PerformJSONPutRequest(ctx context.Context, url string, requestBody []byte) ([]byte, error)
PerformJSONPutRequest performs a PUT request to the specified URL and returns the response body and eventual errors
func (*ClientContext) PerformJSONPutUploadRequest ¶ added in v4.7.0
func (c *ClientContext) PerformJSONPutUploadRequest(ctx context.Context, url string, requestBody io.Reader) ([]byte, error)
PerformJSONPutUploadRequest performs a PUT request to the specified URL with an io.Reader and returns the response body and eventual errors
func (*ClientContext) PerformJSONRequest ¶ added in v4.7.0
func (c *ClientContext) PerformJSONRequest(ctx context.Context, method, url string, body io.Reader) ([]byte, error)
Performs the specified HTTP request with context and returns the response through handleResponse()