Documentation ¶
Index ¶
- Variables
- type Client
- type ClientOptions
- type RequestHook
- type Response
- func Delete(ctx context.Context, target string, query url.Values, body io.Reader, ...) (*Response, error)
- func Get(ctx context.Context, target string, query url.Values, opts ...RequestHook) (*Response, error)
- func Head(ctx context.Context, target string, query url.Values, opts ...RequestHook) (*Response, error)
- func Options(ctx context.Context, target string, query url.Values, opts ...RequestHook) (*Response, error)
- func Post(ctx context.Context, target string, query url.Values, body io.Reader, ...) (*Response, error)
- func Put(ctx context.Context, target string, query url.Values, body io.Reader, ...) (*Response, error)
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = &client{ opts: Defaults(), }
DefaultClient is a Snorlax client configured with all of the default options.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // AddHeader appends a header value to the client to be sent in every // request. To replace the current existing header use SetHeader. AddHeader(key, value string) Client // AddRequestHook appends a RequestHook to the list of hooks which are to be // run just before the client sends a request. RequestHooks are executed in // the order they are added. AddRequestHook(hook RequestHook) Client // AddRequestHooks is a convenience function which calls AddRequestHook // multiple times. AddRequestHooks(hooks ...RequestHook) Client // Get performs a Get request. You can optionally configure the request // using RequestHooks, or by configuring the client if you need to configure // all requests. Delete(ctx context.Context, target string, query url.Values, body io.Reader, hooks ...RequestHook) (*Response, error) // Get performs a Get request. You can optionally configure the request // using RequestHooks, or by configuring the client if you need to configure // all requests. Get(ctx context.Context, target string, query url.Values, hooks ...RequestHook) (*Response, error) // Head performs a Head request. You can optionally configure the request // using RequestHooks, or by configuring the client if you need to configure // all requests. Head(ctx context.Context, target string, query url.Values, hooks ...RequestHook) (*Response, error) // Logger returns the client's internal logger. Logger() *logrus.Logger // Options performs a Options request. You can optionally configure the // request using RequestHooks, or by configuring the client if you need to // configure all requests. Options(ctx context.Context, target string, query url.Values, hooks ...RequestHook) (*Response, error) // Post performs a Post request. You can optionally configure the request // using RequestHooks, or by configuring the client if you need to configure // all requests. Post(ctx context.Context, target string, query url.Values, body io.Reader, hooks ...RequestHook) (*Response, error) // Put performs a Put request. You can optionally configure the request // using RequestHooks, or by configuring the client if you need to configure // all requests. Put(ctx context.Context, target string, query url.Values, body io.Reader, hooks ...RequestHook) (*Response, error) // RemoveProxy removes any currently set proxy URL in the Client's // transport. RemoveProxy() Client // SetBaseURL sets a host URL inside the client which is prepended to all // request URLs performed by the Client. SetBaseURL(url string) Client // SetHeader sets a header value in the client to be sent in every request. // This will overwrite any exiting headers present associated with the same // key. To add headers to the key instead of replacing them use AddHeader. SetHeader(key, value string) Client // SetHTTPClient replaces the internal http.Client that Snorlax uses to // perform requests. Use this if you need finer control over the client's // internals. SetHTTPClient(c *http.Client) Client // SetLogLevel sets the amount of logs the client will produce. The lower // the level, the less logs will be written. By default, Snorlax uses the // lowest possible level - PanicLevel. SetLogLevel(level logrus.Level) Client // SetProxy sets the proxy URL in the clent's transport. If the URL fails // to parse, nothing is set. This function fails silently. If you need more // of a guarantee rather create your own http.Client with your proxy set and // use SetHTTPClient. SetProxy(url string) Client }
Client defines a wrapper around an http.Client making it easier to send requests to RESTful APIs.
func NewClient ¶
func NewClient(opts *ClientOptions) Client
NewClient constructs a new Client configured with the provided ClientOptions.
type ClientOptions ¶
type ClientOptions struct { BaseURL string WithMetrics bool // contains filtered or unexported fields }
ClientOptions contains the configuration options for a Snorlax client.
type RequestHook ¶
RequestHook is a middleware function that can be applied to an HTTP request before it's sent.
func WithBasicAuth ¶
func WithBasicAuth(username, password string) RequestHook
WithBasicAuth sets basic authentication on the request.
func WithHeader ¶
func WithHeader(key, value string) RequestHook
WithHeader adds a the header key value pair to the request.
type Response ¶
Response is a type alias for http.Response.
func Delete ¶
func Delete(ctx context.Context, target string, query url.Values, body io.Reader, hooks ...RequestHook) (*Response, error)
Delete performs a delete request using the DefaultClient. You can optionally configure the request using RequestHooks. If you need to configure every request then consider not using the DefaultClient.
func Get ¶
func Get(ctx context.Context, target string, query url.Values, opts ...RequestHook) (*Response, error)
Get performs a get request using the DefaultClient. You can optionally configure the request using RequestHooks. If you need to configure every request then consider not using the DefaultClient.
func Head ¶
func Head(ctx context.Context, target string, query url.Values, opts ...RequestHook) (*Response, error)
Head performs a head request using the DefaultClient. You can optionally configure the request using RequestHooks. If you need to configure every request then consider not using the DefaultClient.
func Options ¶
func Options(ctx context.Context, target string, query url.Values, opts ...RequestHook) (*Response, error)
Options performs an options request using the DefaultClient. You can optionally configure the request using RequestHooks. If you need to configure every request then consider not using the DefaultClient.
func Post ¶
func Post(ctx context.Context, target string, query url.Values, body io.Reader, opts ...RequestHook) (*Response, error)
Post performs a post request using the DefaultClient. You can optionally configure the request using RequestHooks. If you need to configure every request then consider not using the DefaultClient.
func Put ¶
func Put(ctx context.Context, target string, query url.Values, body io.Reader, opts ...RequestHook) (*Response, error)
Post performs a post request using the DefaultClient. You can optionally configure the request using RequestHooks. If you need to configure every request then consider not using the DefaultClient.