Documentation ¶
Index ¶
- func Do(method, url string, handler ResponseHandler, mod ...Modifier) error
- func Get(url string, handler ResponseHandler, mod ...Modifier) error
- func Post(url string, handler ResponseHandler, mod ...Modifier) error
- func StatusOK(code int, message string) error
- type CallbackWriter
- type ChainWriter
- type Cleaner
- type Cleaners
- type CloseCallbackWriter
- type HTTPError
- type Modifier
- func WithCleaner(cleaner Cleaner) Modifier
- func WithClientOptions(mods ...kclient.Modifier) Modifier
- func WithContent(content io.Reader) Modifier
- func WithContext(ctx context.Context) Modifier
- func WithOptions(mods ...Modifier) Modifier
- func WithRequestOptions(mods ...krequest.Modifier) Modifier
- func WithTimeout(timeout time.Duration) Modifier
- type Modifiers
- type Options
- type ResponseHandler
- type ResponseOpener
- func Buffer(dest *[]byte) ResponseOpener
- func Callback(cb func([]byte) error) ResponseOpener
- func Chain(openers ...ResponseOpener) ResponseOpener
- func File(path string) ResponseOpener
- func Limit(max int64, nested ResponseOpener) ResponseOpener
- func Null() ResponseOpener
- func OnClose(cb func(*http.Response) error) ResponseOpener
- func String(dest *string) ResponseOpener
- func WriteCloser(wc io.WriteCloser) ResponseOpener
- func Writer(wc io.Writer) ResponseOpener
- func WriterCreator(creator func() io.Writer) ResponseOpener
- type ResponseReader
- type StatusChecker
- type StatusCheckers
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
func Do(method, url string, handler ResponseHandler, mod ...Modifier) error
Do performs an http request by applying the specified options.
method is a string, generally one of the http.Method.* constants, indicating the HTTP method to use. url is the remote url to retrieve, as a string. mod is a set of modifiers indicating how to perform the request.
func Get ¶
func Get(url string, handler ResponseHandler, mod ...Modifier) error
Get will perform a GET request to retrieve the specified url by invoking the Do method.
Types ¶
type CallbackWriter ¶
func NewCallbackWriter ¶
func NewCallbackWriter(cb func([]byte) error) *CallbackWriter
func (*CallbackWriter) Close ¶
func (bw *CallbackWriter) Close() error
type ChainWriter ¶
type ChainWriter []io.WriteCloser
func (ChainWriter) Close ¶
func (cw ChainWriter) Close() error
type CloseCallbackWriter ¶
type CloseCallbackWriter struct {
// contains filtered or unexported fields
}
func (CloseCallbackWriter) Close ¶
func (cb CloseCallbackWriter) Close() error
type HTTPError ¶
Returned by Read operations to provide details on the failed operation, by wrapping an existing error.
type Modifier ¶
func WithCleaner ¶
func WithClientOptions ¶
func WithContent ¶
WithContent allows to provide a body to be sent to the remote end.
For example, use WithContent(strings.NewReader("this is some json")) to send some json alongside your POST requests.
func WithContext ¶
func WithOptions ¶
func WithRequestOptions ¶
func WithTimeout ¶
type Options ¶
type ResponseHandler ¶
func Read ¶
func Read(opener ResponseOpener, checker ...StatusChecker) ResponseHandler
func Reader ¶
func Reader(r ResponseReader, checker ...StatusChecker) ResponseHandler
type ResponseOpener ¶
type ResponseOpener func(resp *http.Response) (io.WriteCloser, error)
Opener is a function able to open an output stream.
The size argument indicates how many bytes are expected in this stream. The parameter cannot be trusted, as the remote server is allowed to return any value. 0 indicates the amount of bytes is unknown.
Opener returns an io.WriteCloser(), usable to write the data out, or an error.
func Buffer ¶
func Buffer(dest *[]byte) ResponseOpener
Buffer returns an opener able to write all the data in a []byte array.
func Callback ¶
func Callback(cb func([]byte) error) ResponseOpener
Callback will invoke the specified callback once the write has completed.
func Chain ¶
func Chain(openers ...ResponseOpener) ResponseOpener
func File ¶
func File(path string) ResponseOpener
File returns an Opener able to write to a file. path if the path of the file.
Note that the file will not be opened until the Opener is actually invoked, at which point an error may be returned.
func Limit ¶
func Limit(max int64, nested ResponseOpener) ResponseOpener
Limit returns an opener that will limit the total amount of bytes written to the max specified.
For example, by creating an opener like:
Get(..., Limit(4096, String(&data)), ...)
Get will stop the download and return an error if more than 4096 bytes of data are returned by the remote server.
func Null ¶
func Null() ResponseOpener
Null is an Opener that will discard all the data that it is passed.
func OnClose ¶
func OnClose(cb func(*http.Response) error) ResponseOpener
OnClose will invoke the specified callback on close only.
func String ¶
func String(dest *string) ResponseOpener
String returns an opener able to store data in a string.
func WriteCloser ¶
func WriteCloser(wc io.WriteCloser) ResponseOpener
WriteCloser allows to pass a simple io.WriteCloser without creating an Opener.
func Writer ¶
func Writer(wc io.Writer) ResponseOpener
Writer allows to pass a simple io.Writer without creating an Opener.
func WriterCreator ¶
func WriterCreator(creator func() io.Writer) ResponseOpener
type ResponseReader ¶
type StatusChecker ¶
func StatusRange ¶
func StatusRange(min, max int) StatusChecker
func StatusValue ¶
func StatusValue(expected int) StatusChecker
type StatusCheckers ¶
type StatusCheckers []StatusChecker