client

package
v7.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	Version    string = "7.0.0"
	APIVersion string = "1.3"
	APIBaseURL string = "https://api.upcloud.com"

	EnvDebugAPIBaseURL            string = "UPCLOUD_DEBUG_API_BASE_URL"
	EnvDebugSkipCertificateVerify string = "UPCLOUD_DEBUG_SKIP_CERTIFICATE_VERIFY"
)
View Source
const (
	ErrorTypeError = iota
	ErrorTypeProblem
)

Variables

This section is empty.

Functions

func NewDefaultHTTPClient

func NewDefaultHTTPClient() *http.Client

NewDefaultHTTPClient returns new default http.Client.

func NewDefaultHTTPTransport

func NewDefaultHTTPTransport() http.RoundTripper

NewDefaultHTTPTransport return new HTTP client transport round tripper.

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, c ...ConfigFn) *Client

New creates and returns a new client configured with the specified user and password and optional config functions.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) ([]byte, error)

Delete performs a DELETE request to the specified path and returns the response body.

func (*Client) Do

func (c *Client) Do(r *http.Request) ([]byte, error)

Do performs HTTP request and returns the response body.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) ([]byte, error)

Get performs a GET request to the specified path and returns the response body.

func (*Client) Patch

func (c *Client) Patch(ctx context.Context, path string, body []byte) ([]byte, error)

Patch performs a PATCH request to the specified path and returns the response body.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body []byte) ([]byte, error)

Post performs a POST request to the specified path and returns the response body.

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body []byte) ([]byte, error)

Put performs a PUT request to the specified path and returns the response body.

type ConfigFn

type ConfigFn func(o *config)

func WithBaseURL

func WithBaseURL(baseURL string) ConfigFn

WithBaseURL modifies the client baseURL

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ConfigFn

WithHTTPClient replaces the client's default httpClient with the specified one

Example
httpClient := &http.Client{
	// setup custom HTTP client
}
New(os.Getenv("UPCLOUD_USERNAME"), os.Getenv("UPCLOUD_PASSWORD"), WithHTTPClient(httpClient))
Output:

func WithInsecureSkipVerify

func WithInsecureSkipVerify() ConfigFn

WithInsecureSkipVerify modifies the client's httpClient to skip verifying the server's certificate chain and host name. This should be used only for testing.

func WithTimeout

func WithTimeout(timeout time.Duration) ConfigFn

WithTimeout modifies the client's httpClient timeout

Example
New(os.Getenv("UPCLOUD_USERNAME"), os.Getenv("UPCLOUD_PASSWORD"), WithTimeout(10*time.Second))
Output:

type Error

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

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

type ErrorType

type ErrorType int

Jump to

Keyboard shortcuts

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