Categorygithub.com/2785/fancy-http-client
modulepackage
0.2.0
Repository: https://github.com/2785/fancy-http-client.git
Documentation: pkg.go.dev

# README

Fancy HTTP Client

Golang HTTP Client that satisfies the Doer interface, i.e.

... interface {
    Do(*http.Request) (*http.Response, error)
}

With configurable throttling and / or connection limiting.

Quick Start

Base client with no throttling and connection limit, this is effectively the same as using the base client itself.

baseHC := &http.Client{
    Timeout: 30 * time.Second
}

fhc := fancyhttpclient.New(baseHC)

Client with delay between outgoing requests, this will space out outgoing requests on a 50ms interval. The delay is applied across threads if threads share the same instance of fhc.

fhc := fancyhttpclient.New(baseHC, fancyhttpclient.WithDelay(50*time.Millisecond))

Client with limit to the max number of connections it has to the server, will limit to max 5 connections

fhc := fancyhttpclient.New(baseHC, fancyhttpclient.WithMaxCoon(5))

Or both! This will limit max connection to 5 and space out the outgoing requests by 50ms

fhc := fancyhttpclient.New(
    baseHC, 
    fancyhttpclient.WithDelay(50*time.Millisecond),
    fancyhttpclient.WithMaxCoon(5),
)

It can then be passed to multiple goroutines that each performs individual Do()s, or

reqs := []*http.Request{bunch, of, requests}
responsers, _ := fhc.DoBunch(reqs)
res0, err0 := responsers[0].Response()

# Functions

New returns an instance of FancyHTTPClient according to the delay and timeout provided.
WithDelay sets up the client to space out each requests sent.
WithMaxConn sets up the client to limit its connection to a set number.

# Structs

FancyHTTPClient is a custom HTTP client that is able to handle.
ResponseGetter contains either an http response or an error.

# Interfaces

Doer performs an HTTP request.

# Type aliases

ClientOption apply custom options to the client.