client

package
v5.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const (
	Version    string = "5.4.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 WithBaseURL

func WithBaseURL(baseURL string) configFn

func WithHTTPClient

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

func WithTimeout

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

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

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 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