Documentation
¶
Index ¶
- Constants
- func NewDefaultHTTPClient() *http.Client
- func NewDefaultHTTPTransport() http.RoundTripper
- func NewDefaultTLSClientConfig() *tls.Config
- type Client
- func (c *Client) Delete(ctx context.Context, path string) ([]byte, error)
- func (c *Client) Do(r *http.Request) ([]byte, error)
- func (c *Client) DoStream(r *http.Request) (io.ReadCloser, error)
- func (c *Client) Get(ctx context.Context, path string) ([]byte, error)
- func (c *Client) GetStream(ctx context.Context, path string) (io.ReadCloser, error)
- func (c *Client) Patch(ctx context.Context, path string, body []byte) ([]byte, error)
- func (c *Client) Post(ctx context.Context, path string, body []byte) ([]byte, error)
- func (c *Client) Put(ctx context.Context, path string, body []byte) ([]byte, error)
- type ConfigFn
- func WithBaseURL(baseURL string) ConfigFn
- func WithBasicAuth(username, password string) ConfigFn
- func WithBearerAuth(apiToken string) ConfigFn
- func WithHTTPClient(httpClient *http.Client) ConfigFn
- func WithInsecureSkipVerify() ConfigFn
- func WithLogger(logger LogFn) ConfigFn
- func WithTimeout(timeout time.Duration) ConfigFn
- type Error
- type ErrorType
- type LogFn
Examples ¶
Constants ¶
const ( Version string = "8.34.3" APIVersion string = "1.3" APIBaseURL string = "https://api.upcloud.com" EnvDebugAPIBaseURL string = "UPCLOUD_DEBUG_API_BASE_URL" EnvDebugSkipCertificateVerify string = "UPCLOUD_DEBUG_SKIP_CERTIFICATE_VERIFY" EnvToken string = "UPCLOUD_TOKEN" EnvUsername string = "UPCLOUD_USERNAME" EnvPassword string = "UPCLOUD_PASSWORD" )
const ( ErrorTypeError = iota ErrorTypeProblem )
Variables ¶
This section is empty.
Functions ¶
func NewDefaultHTTPClient ¶
NewDefaultHTTPClient returns new default http.Client.
func NewDefaultHTTPTransport ¶
func NewDefaultHTTPTransport() http.RoundTripper
NewDefaultHTTPTransport return new HTTP client transport round tripper.
func NewDefaultTLSClientConfig ¶ added in v8.32.0
Types ¶
type Client ¶
type Client struct {
UserAgent string
// contains filtered or unexported fields
}
Client represents an API client
func New ¶
New creates and returns a new client configured with the specified user and password and optional config functions. TODO: we should get rid of username, password here, but it's a breaking change. Credentials can be now set with configurators client.WithBasicAuth("user", "pass") or client.WithBearerAuth("ucat_token")
func NewFromEnv ¶ added in v8.19.0
NewFromEnv creates a new client from environment variables and validates that only one authentication method is provided.
func (*Client) Delete ¶
Delete performs a DELETE request to the specified path and returns the response body.
func (*Client) DoStream ¶ added in v8.20.0
DoStream performs HTTP request and returns the response body reader.
func (*Client) Get ¶
Get performs a GET request to the specified path and returns the response body.
func (*Client) GetStream ¶ added in v8.20.0
GetStream performs a GET request to the specified path and returns the response body reader.
func (*Client) Patch ¶
Patch performs a PATCH request to the specified path and returns the response body.
type ConfigFn ¶
type ConfigFn func(o *config)
func WithBaseURL ¶
WithBaseURL modifies the client baseURL
func WithBasicAuth ¶ added in v8.16.0
WithBasicAuth configures the client to use basic auth credentials for authentication
func WithBearerAuth ¶ added in v8.16.0
WithBearerAuth (EXPERIMENTAL) configures the client to use bearer token for authentication
func WithHTTPClient ¶
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))
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 WithLogger ¶ added in v8.10.0
WithLogger configures logging function that logs requests and responses