Documentation ¶
Index ¶
- func BodyEmpty(io.Writer) (string, string, error)
- func StatusIn(code int, rest ...int) func(*http.Response) error
- type BodyFn
- type Client
- func (c *Client) Clone(opts ...ClientOptFn) (*Client, error)
- func (c *Client) Delete(urlPath ...string) *Req
- func (c *Client) Get(urlPath ...string) *Req
- func (c *Client) Patch(bFn BodyFn, urlPath ...string) *Req
- func (c *Client) PatchJSON(v interface{}, urlPath ...string) *Req
- func (c *Client) Post(bFn BodyFn, urlPath ...string) *Req
- func (c *Client) PostJSON(v interface{}, urlPath ...string) *Req
- func (c *Client) Put(bFn BodyFn, urlPath ...string) *Req
- func (c *Client) PutJSON(v interface{}, urlPath ...string) *Req
- func (c *Client) Req(method string, bFn BodyFn, urlPath ...string) *Req
- type ClientOptFn
- func WithAddr(addr string) ClientOptFn
- func WithAuth(fn func(r *http.Request)) ClientOptFn
- func WithAuthToken(token string) ClientOptFn
- func WithContentType(ct string) ClientOptFn
- func WithHTTPClient(c *http.Client) ClientOptFn
- func WithHeader(header, val string) ClientOptFn
- func WithInsecureSkipVerify(b bool) ClientOptFn
- func WithRespFn(fn func(*http.Response) error) ClientOptFn
- func WithSessionCookie(session string) ClientOptFn
- func WithStatusFn(fn func(*http.Response) error) ClientOptFn
- func WithWriterFn(fn WriteCloserFn) ClientOptFn
- func WithWriterGZIP() ClientOptFn
- type Req
- func (r *Req) Accept(contentType string) *Req
- func (r *Req) ContentType(contentType string) *Req
- func (r *Req) Decode(fn func(resp *http.Response) error) *Req
- func (r *Req) DecodeGob(v interface{}) *Req
- func (r *Req) DecodeJSON(v interface{}) *Req
- func (r *Req) Do(ctx context.Context) error
- func (r *Req) Header(k, v string) *Req
- func (r *Req) Headers(m map[string][]string) *Req
- func (r *Req) QueryParams(pairs ...[2]string) *Req
- func (r *Req) RespFn(fn func(*http.Response) error) *Req
- func (r *Req) StatusFn(fn func(*http.Response) error) *Req
- type WriteCloserFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BodyFn ¶
BodyFn provides a writer to which a value will be written to that will make it's way into the HTTP request.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a basic http client that can make cReqs with out having to juggle the token and so forth. It provides sane defaults for checking response statuses, sets auth token when provided, and sets the content type to application/json for each request. The token, response checker, and content type can be overridden on the Req as well.
func (*Client) Clone ¶
func (c *Client) Clone(opts ...ClientOptFn) (*Client, error)
Clone creates a new *Client type from an existing client. This may be useful if you want to have a shared base client, then take a specific client from that base and tack on some extra goodies like specific headers and whatever else that suits you. Note: a new net.http.Client type will not be created. It will share the existing http.Client from the parent httpc.Client. Same connection pool, different specifics.
func (*Client) PatchJSON ¶
PatchJSON generates a PATCH request. This is to be used with value or pointer to value type. Providing a stream/reader will result in disappointment.
func (*Client) PostJSON ¶
PostJSON generates a POST request and json encodes the body. This is to be used with value or pointer to value type. Providing a stream/reader will result in disappointment.
type ClientOptFn ¶
type ClientOptFn func(*clientOpt) error
ClientOptFn are options to set different parameters on the Client.
func WithAddr ¶
func WithAddr(addr string) ClientOptFn
WithAddr sets the host address on the client.
func WithAuth ¶
func WithAuth(fn func(r *http.Request)) ClientOptFn
WithAuth provides a means to set a custom auth that doesn't match the provided auth types here.
func WithAuthToken ¶
func WithAuthToken(token string) ClientOptFn
WithAuthToken provides token auth for requests.
func WithContentType ¶
func WithContentType(ct string) ClientOptFn
WithContentType sets the content type that will be applied to the requests created by the Client.
func WithHTTPClient ¶
func WithHTTPClient(c *http.Client) ClientOptFn
WithHTTPClient sets the raw http client on the httpc Client.
func WithHeader ¶
func WithHeader(header, val string) ClientOptFn
WithHeader sets a default header that will be applied to all requests created by the client.
func WithInsecureSkipVerify ¶
func WithInsecureSkipVerify(b bool) ClientOptFn
WithInsecureSkipVerify sets the insecure skip verify on the http client's htp transport.
func WithRespFn ¶
func WithRespFn(fn func(*http.Response) error) ClientOptFn
WithRespFn sets the default resp fn for the client that will be applied to all requests generated from it.
func WithSessionCookie ¶
func WithSessionCookie(session string) ClientOptFn
WithSessionCookie provides cookie auth for requests to mimic the browser. Typically, session is influxdb.Session.Key.
func WithStatusFn ¶
func WithStatusFn(fn func(*http.Response) error) ClientOptFn
WithStatusFn sets the default status fn for the client that will be applied to all requests generated from it.
func WithWriterFn ¶
func WithWriterFn(fn WriteCloserFn) ClientOptFn
WithWriterFn applies the provided writer behavior to all the request bodies' generated from the client.
func WithWriterGZIP ¶
func WithWriterGZIP() ClientOptFn
WithWriterGZIP gzips the request body generated from this client.
type Req ¶
type Req struct {
// contains filtered or unexported fields
}
Req is a request type.
func (*Req) ContentType ¶
ContentType sets the Content-Type header to the provided content type on the request.
func (*Req) Decode ¶
Decode sets the decoding functionality for the request. All Decode calls are called after the status and response functions are called. Decoding will not happen if error encountered in the status check.
func (*Req) DecodeJSON ¶
DecodeJSON sets the decoding functionality to decode json for the request.
func (*Req) Do ¶
Do makes the HTTP request. Any errors that had been encountered in the lifetime of the Req type will be returned here first, in place of the call. This makes it safe to call Do at anytime.
func (*Req) QueryParams ¶
QueryParams adds the query params to the http request.
type WriteCloserFn ¶
type WriteCloserFn func(closer io.WriteCloser) (string, string, io.WriteCloser)
WriteCloserFn is a write closer wrapper than indicates the type of writer by returning the header and header value associated with the writer closer.
i.e. GZIP writer returns header Content-Encoding with value gzip alongside the writer.