internal

package
v0.0.0-...-22d1802 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks errors if exist errors in request

Types

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// User agent for httpClient
	UserAgent string

	// error message, incase httpClient is in error state
	ErrorMsg string
	// contains filtered or unexported fields
}

Client Config Configuration of the httpClient

func NewClient

func NewClient(opts ...ClientOption) (*Client, error)

NewClient returns a wrapper around http/https (as per isHTTP flag) httpClient with additions of proxy & session_auth if given

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) error

Do performs request passed

func (*Client) DoWithFilters

func (c *Client) DoWithFilters(ctx context.Context, req *http.Request, v interface{}, filters []*vmclient.AdditionalFilter, baseSearchPaths []string) error

DoWithFilters performs request passed and filters entities in json response

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates a request

func (*Client) NewUnAuthFormEncodedRequest

func (c *Client) NewUnAuthFormEncodedRequest(method, urlStr string, body map[string]string) (*http.Request, error)

NewUnAuthFormEncodedRequest returns content-type: application/x-www-form-urlencoded based unauth request

func (*Client) NewUnAuthRequest

func (c *Client) NewUnAuthRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewUnAuthRequest creates a request without authorisation headers

func (*Client) NewUnAuthUploadRequest

func (c *Client) NewUnAuthUploadRequest(method, urlStr string, fileReader *os.File) (*http.Request, error)

NewUploadRequest handles image uploads for image service

func (*Client) NewUploadRequest

func (c *Client) NewUploadRequest(method, urlStr string, fileReader *os.File) (*http.Request, error)

NewUploadRequest Handles image uploads for image service

func (*Client) OnRequestCompleted

func (c *Client) OnRequestCompleted(rc RequestCompletionCallback)

OnRequestCompleted sets the DO API request completion callback

type ClientOption

type ClientOption func(*Client) error

func WithAbsolutePath

func WithAbsolutePath(absolutePath string) ClientOption

WithAbsolutePath sets the absolute path for the httpClient to communicate with

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL sets the base URL for the httpClient to communicate with

func WithCertificate

func WithCertificate(cert *x509.Certificate) ClientOption

WithCertificate adds the certificate to the certificate pool in tls config

func WithCookies

func WithCookies(cookies []*http.Cookie) ClientOption

WithCookies sets the cookies for the httpClient

func WithCredentials

func WithCredentials(credentials *vmclient.Credentials) ClientOption

WithCredentials sets the credentials for the httpClient

func WithLogger

func WithLogger(logger *logr.Logger) ClientOption

WithLogger sets the logger for the httpClient

func WithRoundTripper

func WithRoundTripper(transport http.RoundTripper) ClientOption

WithRoundTripper overrides the transport for the httpClient Overriding transport is useful for testing against API Mocks This is not recommended for production use

func WithUserAgent

func WithUserAgent(userAgent string) ClientOption

WithUserAgent sets the user agent for the httpClient

type ErrorResponse

type ErrorResponse struct {
	APIVersion  string            `json:"api_version,omitempty"`
	Code        int64             `json:"code,omitempty"`
	Kind        string            `json:"kind,omitempty"`
	MessageList []MessageResource `json:"message_list"`
	State       string            `json:"state"`
}

ErrorResponse ...

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type MessageResource

type MessageResource struct {
	// Custom key-value details relevant to the status.
	Details interface{} `json:"details,omitempty"`

	// If state is ERROR, a message describing the error.
	Message string `json:"message"`

	// If state is ERROR, a machine-readable snake-cased *string.
	Reason string `json:"reason"`
}

MessageResource ...

type RequestCompletionCallback

type RequestCompletionCallback func(*http.Request, *http.Response, interface{})

RequestCompletionCallback defines the type of the request callback function

type Scheme

type Scheme string
const (
	SchemeHTTP  Scheme = "http"
	SchemeHTTPS Scheme = "https"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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