astihttp

package
v0.0.0-...-6a70e61 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChainMiddlewares

func ChainMiddlewares(h http.Handler, ms ...Middleware) http.Handler

ChainMiddlewares chains middlewares

func ChainMiddlewaresWithPrefix

func ChainMiddlewaresWithPrefix(h http.Handler, prefixes []string, ms ...Middleware) http.Handler

ChainMiddlewaresWithPrefix chains middlewares if one of prefixes is present

func ChainRouterMiddlewares

func ChainRouterMiddlewares(h httprouter.Handle, ms ...RouterMiddleware) httprouter.Handle

ChainRouterMiddlewares chains router middlewares

func ChainRouterMiddlewaresWithPrefix

func ChainRouterMiddlewaresWithPrefix(h httprouter.Handle, prefixes []string, ms ...RouterMiddleware) httprouter.Handle

ChainRouterMiddlewares chains router middlewares if one of prefixes is present

func Download

func Download(ctx context.Context, c *http.Client, src, dst string) (err error)

Download is a cancellable function that downloads a src into a dst using a specific *http.Client

func DownloadInWriter

func DownloadInWriter(ctx context.Context, c *http.Client, src string, dst io.Writer) (err error)

DownloadInWriter is a cancellable function that downloads a src into a writer using a specific *http.Client

func Serve

func Serve(ctx context.Context, h http.Handler, addr string, fn func(a net.Addr)) (err error)

Types

type Downloader

type Downloader struct {
	// contains filtered or unexported fields
}

Downloader represents a downloader

func NewDownloader

func NewDownloader(o DownloaderOptions) (d *Downloader)

NewDownloader creates a new downloader

func (*Downloader) Download

func (d *Downloader) Download(parentCtx context.Context, paths []string, fn DownloaderFunc) (err error)

Download downloads in parallel a set of src paths and executes a custom callback on each downloaded buffers

func (*Downloader) DownloadInDirectory

func (d *Downloader) DownloadInDirectory(ctx context.Context, dst string, paths ...string) error

DownloadInDirectory downloads in parallel a set of src paths and saves them in a dst directory

func (*Downloader) DownloadInFile

func (d *Downloader) DownloadInFile(ctx context.Context, dst string, paths ...string) (err error)

DownloadInFile downloads in parallel a set of src paths and concatenates them in order in a writer

func (*Downloader) DownloadInWriter

func (d *Downloader) DownloadInWriter(ctx context.Context, w io.Writer, paths ...string) (err error)

DownloadInWriter downloads in parallel a set of src paths and concatenates them in order in a writer

type DownloaderFunc

type DownloaderFunc func(ctx context.Context, idx int, src string, r io.ReadCloser) error

DownloaderFunc represents a downloader func It's its responsibility to close the reader

type DownloaderOptions

type DownloaderOptions struct {
	IgnoreErrors    bool
	NumberOfWorkers int
	Sender          SenderOptions
}

DownloaderOptions represents downloader options

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware represents a middleware

func MiddlewareBasicAuth

func MiddlewareBasicAuth(username, password string) Middleware

MiddlewareBasicAuth adds basic HTTP auth to a handler

func MiddlewareContentType

func MiddlewareContentType(contentType string) Middleware

MiddlewareContentType adds a content type to a handler

func MiddlewareHeaders

func MiddlewareHeaders(vs map[string]string) Middleware

MiddlewareHeaders adds headers to a handler

func MiddlewareTimeout

func MiddlewareTimeout(timeout time.Duration) Middleware

MiddlewareTimeout adds a timeout to a handler

type RetryFunc

type RetryFunc func(name string, resp *http.Response) bool

RetryFunc is a function that decides whether to retry the request

type RouterMiddleware

type RouterMiddleware func(httprouter.Handle) httprouter.Handle

RouterMiddleware represents a router middleware

func RouterMiddlewareBasicAuth

func RouterMiddlewareBasicAuth(username, password string) RouterMiddleware

RouterMiddlewareBasicAuth adds basic HTTP auth to a router handler

func RouterMiddlewareContentType

func RouterMiddlewareContentType(contentType string) RouterMiddleware

RouterMiddlewareContentType adds a content type to a router handler

func RouterMiddlewareHeaders

func RouterMiddlewareHeaders(vs map[string]string) RouterMiddleware

RouterMiddlewareHeaders adds headers to a router handler

func RouterMiddlewareTimeout

func RouterMiddlewareTimeout(timeout time.Duration) RouterMiddleware

RouterMiddlewareTimeout adds a timeout to a router handler

type Sender

type Sender struct {
	// contains filtered or unexported fields
}

Sender represents an object capable of sending http requests

func NewSender

func NewSender(o SenderOptions) (s *Sender)

NewSender creates a new sender

func (*Sender) ExecWithRetry

func (s *Sender) ExecWithRetry(name string, fn func() (*http.Response, error)) (resp *http.Response, err error)

ExecWithRetry handles retrying when fetching a response name is used for logging purposes only

func (*Sender) Send

func (s *Sender) Send(req *http.Request) (resp *http.Response, err error)

Send sends a new *http.Request

func (*Sender) SendCtx

func (s *Sender) SendCtx(ctx context.Context, req *http.Request) (resp *http.Response, err error)

SendCtx sends a new *http.Request with a context

type SenderOptions

type SenderOptions struct {
	Client     *http.Client
	RetryFunc  RetryFunc
	RetryMax   int
	RetrySleep time.Duration
}

SenderOptions represents sender options

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL