Documentation ¶
Index ¶
- Variables
- type 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
- type Opts
- type ProtocolError
- type RequestOpt
- type RequestOpts
- type Response
- type ResponseHandler
Constants ¶
This section is empty.
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) )
Functions ¶
This section is empty.
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 ¶ added in v0.0.4
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.
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 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.
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 DefaultHeader ¶
DefaultHeader returns an Opt that adds a header to an Client's headers.
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.
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 ¶ added in v0.0.4
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.