Documentation ¶
Index ¶
- func CheckResponse(r *http.Response) error
- type Client
- func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) error
- func (c *Client) DoWithFilters(ctx context.Context, req *http.Request, v interface{}, ...) error
- func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)
- func (c *Client) NewUnAuthFormEncodedRequest(method, urlStr string, body map[string]string) (*http.Request, error)
- func (c *Client) NewUnAuthRequest(method, urlStr string, body interface{}) (*http.Request, error)
- func (c *Client) NewUnAuthUploadRequest(method, urlStr string, fileReader *os.File) (*http.Request, error)
- func (c *Client) NewUploadRequest(method, urlStr string, fileReader *os.File) (*http.Request, error)
- func (c *Client) OnRequestCompleted(rc RequestCompletionCallback)
- type ClientOption
- func WithAbsolutePath(absolutePath string) ClientOption
- func WithBaseURL(baseURL string) ClientOption
- func WithCertificate(cert *x509.Certificate) ClientOption
- func WithCookies(cookies []*http.Cookie) ClientOption
- func WithCredentials(credentials *vmclient.Credentials) ClientOption
- func WithLogger(logger *logr.Logger) ClientOption
- func WithRoundTripper(transport http.RoundTripper) ClientOption
- func WithUserAgent(userAgent string) ClientOption
- type ErrorResponse
- type MessageResource
- type RequestCompletionCallback
- type Scheme
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶
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) 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 ¶
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 ¶
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 ¶
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 ¶
RequestCompletionCallback defines the type of the request callback function