httpclient

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2020 License: Apache-2.0 Imports: 15 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client is an HTTP client.

func New

func New(baseURL string, opts ...Option) *Client

New returns a new HTTP client for a given baseURL and functional options.

func (*Client) BaseClient

func (c *Client) BaseClient() *http.Client

BaseClient returns the base client.

func (*Client) BaseURL

func (c *Client) BaseURL() *url.URL

BaseURL returns the HTTP client's base URL.

func (*Client) Delete

func (c *Client) Delete(path string, opts ...Option) (*http.Response, error)

Delete issues a DELETE to the specified DC/OS cluster path.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends an HTTP request and returns an HTTP response, following policy (such as redirects, cookies, auth) as configured on the client.

func (*Client) Get

func (c *Client) Get(path string, opts ...Option) (*http.Response, error)

Get issues a GET to the specified DC/OS cluster path.

func (*Client) Header

func (c *Client) Header() http.Header

Header returns the HTTP client's header.

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, body io.Reader, opts ...Option) (*http.Request, error)

NewRequest returns a new Request given a method, path, and optional body. Also adds the authorization header with the ACS token to work with the DC/OS cluster we are linked to if it has been set.

func (*Client) Post

func (c *Client) Post(path string, contentType string, body io.Reader, opts ...Option) (*http.Response, error)

Post issues a POST to the specified DC/OS cluster path.

func (*Client) Put

func (c *Client) Put(path string, contentType string, body io.Reader, opts ...Option) (*http.Response, error)

Put issues a PUT to the specified DC/OS cluster path.

type HTTPError

type HTTPError struct {
	Response *http.Response
}

HTTPError represents an HTTP error, it is returned when FailOnErrStatus is enabled.

func (*HTTPError) Error

func (err *HTTPError) Error() string

Error returns the error message.

type Option

type Option func(opts *Options)

Option is a functional option for an HTTP client.

func ACSToken

func ACSToken(token string) Option

ACSToken sets the authentication token for HTTP requests.

func FailOnErrStatus

func FailOnErrStatus(failOnErrStatus bool) Option

FailOnErrStatus specifies whether or not the client should fail on HTTP error response (4XX / 5XX).

func Header(key, value string) Option

Header sets an HTTP header.

func Logger

func Logger(logger *logrus.Logger) Option

Logger sets the logger for the HTTP client.

func NoFollow

func NoFollow() Option

NoFollow prevents the client to follow redirect responses.

func TLS

func TLS(tlsConfig *tls.Config) Option

TLS sets the TLS configuration for the HTTP client transport.

func Timeout

func Timeout(timeout time.Duration) Option

Timeout sets the timeout for HTTP requests.

type Options

type Options struct {
	Header          http.Header
	Timeout         time.Duration
	TLS             *tls.Config
	Logger          *logrus.Logger
	CheckRedirect   func(req *http.Request, via []*http.Request) error
	FailOnErrStatus bool
}

Options are configuration options for an HTTP client.

Jump to

Keyboard shortcuts

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