client

package
v0.0.0-...-cc664e3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultAPIVersion = "1.3.6"
	DefaultAPIBaseURL = "https://api.upcloud.com"

	// The default timeout (in seconds)
	DefaultTimeout = 60
)

Constants

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

func New(userName, password string) *Client

New creates ands returns a new client configured with the specified user and password

func NewWithHTTPClient

func NewWithHTTPClient(userName string, password string, httpClient *http.Client) *Client

NewWithHTTPClient creates ands returns a new client configured with the specified user and password and using a supplied `http.Client`.

func (*Client) AddRequestHeaders

func (c *Client) AddRequestHeaders(request *http.Request) *http.Request

Adds common headers to the specified request

func (*Client) CreateRequestURL

func (c *Client) CreateRequestURL(location string) string

CreateRequestURL creates and returns a complete request URL for the specified API location using a newer API version

func (*Client) GetTimeout

func (c *Client) GetTimeout() time.Duration

GetTimeout returns current timeout

func (*Client) PerformJSONDeleteRequest

func (c *Client) PerformJSONDeleteRequest(url string) error

PerformJSONDeleteRequest performs a DELETE request to the specified URL and returns eventual errors

func (*Client) PerformJSONDeleteRequestWithResponseBody

func (c *Client) PerformJSONDeleteRequestWithResponseBody(url string) ([]byte, error)

PerformJSONDeleteRequestWithResponseBody performs a DELETE request to the specified URL and returns the response body and eventual errors

func (*Client) PerformJSONGetRequest

func (c *Client) PerformJSONGetRequest(url string) ([]byte, error)

PerformJSONGetRequest performs a GET request to the specified URL and returns the response body and eventual errors

func (*Client) PerformJSONPatchRequest

func (c *Client) PerformJSONPatchRequest(url string, requestBody []byte) ([]byte, error)

PerformJSONPatchRequest performs a PATCH request to the specified URL and returns the response body and eventual errors

func (*Client) PerformJSONPostRequest

func (c *Client) PerformJSONPostRequest(url string, requestBody []byte) ([]byte, error)

PerformJSONPostRequest performs a POST request to the specified URL and returns the response body and eventual errors

func (*Client) PerformJSONPutRequest

func (c *Client) PerformJSONPutRequest(url string, requestBody []byte) ([]byte, error)

PerformJSONPutRequest performs a PUT request to the specified URL and returns the response body and eventual errors

func (*Client) PerformJSONPutUploadRequest

func (c *Client) PerformJSONPutUploadRequest(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 (*Client) PerformRequest

func (c *Client) PerformRequest(request *http.Request) ([]byte, error)

Performs the specified HTTP request and returns the response through handleResponse()

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration)

SetTimeout sets the client timeout to the specified amount of seconds

type Error

type Error struct {
	ErrorCode    int
	ErrorMessage string
	ResponseBody []byte
}

Error represents an error returned from the client. Errors are thrown when requests don't have a successful status code

func (*Error) Error

func (e *Error) Error() string

Error implements the Error interface

Jump to

Keyboard shortcuts

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