package httpcli
import "github.com/mesos/mesos-go/api/v1/lib/httpcli"
Index ¶
- Variables
- type Client
- func New(opts ...Opt) *Client
- func (c *Client) Do(m encoding.Marshaler, opt ...RequestOpt) (res mesos.Response, err error)
- func (c *Client) Endpoint() string
- func (c *Client) HandleResponse(res *http.Response, rc client.ResponseClass, err error) (mesos.Response, error)
- func (c *Client) Mesos(opts ...RequestOpt) mesos.Client
- func (c *Client) Send(cr client.Request, rc client.ResponseClass, opt ...RequestOpt) (res mesos.Response, err error)
- func (c *Client) With(opts ...Opt) Opt
- func (c *Client) WithTemporary(opt Opt, f func() error) error
- type Config
- type ConfigOpt
- func BasicAuth(username, passwd string) ConfigOpt
- func RoundTripper(rt http.RoundTripper) ConfigOpt
- func TLSConfig(tc *tls.Config) ConfigOpt
- func Timeout(d time.Duration) ConfigOpt
- func Transport(modifyTransport func(*http.Transport)) ConfigOpt
- func WrapRoundTripper(f func(http.RoundTripper) http.RoundTripper) ConfigOpt
- type DoFunc
- type ErrorMapperFunc
- type HTTPRequestHelper
- type Opt
- func Codec(codec encoding.Codec) Opt
- func DefaultHeader(k, v string) Opt
- func Do(do DoFunc) Opt
- func Endpoint(rawurl string) Opt
- func ErrorMapper(em ErrorMapperFunc) Opt
- func HandleResponse(f ResponseHandler) Opt
- func RequestOptions(opts ...RequestOpt) Opt
- func WrapDoer(f func(DoFunc) DoFunc) Opt
- func (o Opt) And(other Opt) Opt
- func (o Opt) Apply(c *Client) (result Opt)
- type Opts
- type ProtocolError
- type RequestOpt
- func Close(b bool) RequestOpt
- func Context(ctx context.Context) RequestOpt
- func Header(k, v string) RequestOpt
- type RequestOpts
- type Response
- type ResponseHandler
Variables ¶
var ( DefaultCodec = codecs.ByMediaType[codecs.MediaTypeProtobuf] DefaultHeaders = http.Header{} // DefaultConfigOpt represents the default client config options. DefaultConfigOpt = []ConfigOpt{ Transport(func(t *http.Transport) { t.ResponseHeaderTimeout = 15 * time.Second t.MaxIdleConnsPerHost = 2 }), } DefaultErrorMapper = ErrorMapperFunc(apierrors.FromResponse) )
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client is a Mesos HTTP APIs client.
func New ¶
New returns a new Client with the given Opts applied. Callers are expected to configure the URL, Do, and Codec options prior to invoking Do.
func (*Client) Do ¶
func (c *Client) Do(m encoding.Marshaler, opt ...RequestOpt) (res mesos.Response, err error)
Do is deprecated in favor of Send.
func (*Client) Endpoint ¶
Endpoint returns the current Mesos API endpoint URL that the caller is set to invoke
func (*Client) HandleResponse ¶
func (c *Client) HandleResponse(res *http.Response, rc client.ResponseClass, err error) (mesos.Response, error)
HandleResponse parses an HTTP response from a Mesos service endpoint, transforming the raw HTTP response into a mesos.Response.
func (*Client) Mesos ¶
func (c *Client) Mesos(opts ...RequestOpt) mesos.Client
Mesos returns a mesos.Client variant backed by this implementation. Deprecated.
func (*Client) Send ¶
func (c *Client) Send(cr client.Request, rc client.ResponseClass, opt ...RequestOpt) (res mesos.Response, err error)
Send sends a Call and returns (a) a Response (should be closed when finished) that contains a either a streaming or non-streaming Decoder from which callers can read objects from, and; (b) an error in case of failure. Callers are expected to *always* close a non-nil Response if one is returned. For operations which are successful but also for which there are no expected result objects the embedded Decoder will be nil. The provided ResponseClass determines whether the client implementation will attempt to decode a result as a single obeject or as an object stream. When working with versions of Mesos prior to v1.2.x callers MUST use ResponseClassAuto.
func (*Client) With ¶
With applies the given Opts to a Client and returns itself.
func (*Client) WithTemporary ¶
WithTemporary configures the Client with the temporary option and returns the results of invoking f(). Changes made to the Client by the temporary option are reverted before this func returns. It is not safe to modify the configuration of a Client as long as said Client is in use by multiple goroutines.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
type ConfigOpt ¶
type ConfigOpt func(*Config)
func BasicAuth ¶
BasicAuth generates a functional config option that sets HTTP Basic authentication for a Client
func RoundTripper ¶
func RoundTripper(rt http.RoundTripper) ConfigOpt
RoundTripper returns a ConfigOpt that sets a Config's round-tripper.
func TLSConfig ¶
TLSConfig returns a ConfigOpt that sets a Config's TLS configuration.
func Timeout ¶
Timeout returns an ConfigOpt that sets a Config's response header timeout, tls handshake timeout, and dialer timeout.
func Transport ¶
Transport returns a ConfigOpt that allows tweaks of the default Config's http.Transport
func WrapRoundTripper ¶
func WrapRoundTripper(f func(http.RoundTripper) http.RoundTripper) ConfigOpt
WrapRoundTripper allows a caller to customize a configuration's HTTP exchanger. Useful for authentication protocols that operate over stock HTTP.
type DoFunc ¶
DoFunc sends an HTTP request and returns an HTTP response.
An error is returned if caused by client policy (such as http.Client.CheckRedirect), or if there was an HTTP protocol error. A non-2xx response doesn't cause an error.
When err is nil, resp always contains a non-nil resp.Body.
Callers should close resp.Body when done reading from it. If resp.Body is not closed, an underlying RoundTripper (typically Transport) may not be able to re-use a persistent TCP connection to the server for a subsequent "keep-alive" request.
The request Body, if non-nil, will be closed by an underlying Transport, even on errors.
func With ¶
With returns a DoFunc that executes HTTP round-trips. The default implementation provides reasonable defaults for timeouts: keep-alive, connection, request/response read/write, and TLS handshake. Callers can customize configuration by specifying one or more ConfigOpt's.
type ErrorMapperFunc ¶
ErrorMapperFunc generates an error for the given response.
type HTTPRequestHelper ¶
HTTPRequestHelper wraps an http.Request and provides utility funcs to simplify code elsewhere
type Opt ¶
Opt defines a functional option for the HTTP client type. A functional option must return an Opt that acts as an "undo" if applied to the same Client.
func Codec ¶
Codec returns an Opt that sets a Client's Codec.
func DefaultHeader ¶
DefaultHeader returns an Opt that adds a header to an Client's headers.
func Do ¶
Do returns an Opt that sets a Client's DoFunc
func Endpoint ¶
Endpoint returns an Opt that sets a Client's URL.
func ErrorMapper ¶
func ErrorMapper(em ErrorMapperFunc) Opt
ErrorMapper returns am Opt that overrides the existing error mapping behavior of the client.
func HandleResponse ¶
func HandleResponse(f ResponseHandler) Opt
HandleResponse returns a functional config option to set the HTTP response handler of the client.
func RequestOptions ¶
func RequestOptions(opts ...RequestOpt) Opt
RequestOptions returns an Opt that applies the given set of options to every Client request.
func WrapDoer ¶
WrapDoer returns an Opt that decorates a Client's DoFunc
func (Opt) And ¶
And combines two functional options into a single Opt
func (Opt) Apply ¶
Apply is a nil-safe application of an Opt: if the receiver is nil then this func simply returns nil, otherwise it returns the result invoking the receiving Opt with the given Client.
type Opts ¶
type Opts []Opt
Opts represents a series of functional options
func (Opts) Merged ¶
Merged generates a single Opt that applies all the functional options, in-order
type ProtocolError ¶
type ProtocolError string
ProtocolError is returned when we receive a response from Mesos that is outside of the HTTP API specification. Receipt of the following will yield protocol errors:
- any unexpected non-error HTTP response codes (e.g. 199)
- any unexpected Content-Type
func (ProtocolError) Error ¶
func (pe ProtocolError) Error() string
Error implements error interface
type RequestOpt ¶
RequestOpt defines a functional option for an http.Request.
func Close ¶
func Close(b bool) RequestOpt
Close returns a RequestOpt that determines whether to close the underlying connection after sending the request.
func Context ¶
func Context(ctx context.Context) RequestOpt
Context returns a RequestOpt that sets the request's Context (ctx must be non-nil)
func Header ¶
func Header(k, v string) RequestOpt
Header returns an RequestOpt that adds a header value to an HTTP requests's header.
type RequestOpts ¶
type RequestOpts []RequestOpt
RequestOpts is a convenience type
func (RequestOpts) Apply ¶
func (opts RequestOpts) Apply(req *http.Request)
Apply this set of request options to the given HTTP request.
type Response ¶
Response captures the output of a Mesos HTTP API operation. Callers are responsible for invoking Close when they're finished processing the response otherwise there may be connection leaks.
type ResponseHandler ¶
ResponseHandler is invoked to process an HTTP response. Callers SHALL invoke Close for a non-nil Response, even when errors are returned.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
api/v1/lib/httpcli/apierrors | |
api/v1/lib/httpcli/httpagent | |
api/v1/lib/httpcli/httpexec | |
api/v1/lib/httpcli/httpmaster | |
api/v1/lib/httpcli/httpsched |
- Version
- v0.0.11 (latest)
- Published
- May 15, 2020
- Platform
- linux/amd64
- Imports
- 18 packages
- Last checked
- 8 hours ago –
Tools for package owners.