restrictedhttpclient

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: MIT Imports: 6 Imported by: 2

README

Restricted HTTP Client

This library is wrapper to restrict the number of requests made by the Golang default HTTP Client. The main idea to develop this is to provide a way to preserve resources on servers that not has protections against a large number of connections .

Documentation

As a wrapper, it has the same public functions from the GO's http client library: https://golang.org/pkg/net/http/#Client

Example:

c := &restrictedhttpclient.Configuration{
	MaxSimultaneousRequests:   10,
	RequestTimeout:            *funks.ForceNewStringDuration("5s"),
	SkipCertificateValidation: true,
}
client, err := restrictedhttpclient.New(c)
if err != nil {
    panic(err)
}
res, err := client.Get("https://www.uol.com.br")
...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNullConfiguration - raised when the specified configuration is null
	ErrNullConfiguration error = errors.New("configuration is null")

	// ErrInvalidNumSimultaneousRequests - raised when the number of simultaneous requests is invalid
	ErrInvalidNumSimultaneousRequests error = errors.New("the number of simultaneous requests is invalid")

	// ErrInvalidRequestTimeout - raised when the request timeout is invalid
	ErrInvalidRequestTimeout error = errors.New("the request timeout is invalid")
)
View Source
var ErrMaxRequestsReached error = errors.New("the maximum number of requests was reached")

ErrMaxRequestsReached - raised when the maximum number of requests was reached

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	// MaxSimultaneousRequests - the maximum number of simultaneous running requests
	MaxSimultaneousRequests uint64 `json:"maxSimultaneousRequests"`

	// RequestTimeout - the maximum request time
	RequestTimeout funks.Duration `json:"requestTimeout"`

	// SkipCertificateValidation - enable/disable certificate validation check
	SkipCertificateValidation bool `json:"skipCertificateValidation"`
}

Configuration - the connection pool configuration

func (*Configuration) Validate

func (c *Configuration) Validate() error

Validate - validates the configuration

type Instance

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

Instance - a pool instance

func New

func New(configuration *Configuration) (*Instance, error)

New - creates a new http connection pool

func (*Instance) CloseIdleConnections

func (i *Instance) CloseIdleConnections()

CloseIdleConnections - wrapper for the Client.CloseIdleConnections

func (*Instance) Do

func (i *Instance) Do(req *http.Request) (resp *http.Response, err error)

Do - wrapper for the Client.Do

func (*Instance) Get

func (i *Instance) Get(url string) (resp *http.Response, err error)

Get - wrapper for the Client.Get

func (*Instance) Head

func (i *Instance) Head(url string) (resp *http.Response, err error)

Head - wrapper for the Client.Head

func (*Instance) Post

func (i *Instance) Post(url, contentType string, body io.Reader) (resp *http.Response, err error)

Post - wrapper for the Client.Post

func (*Instance) PostForm

func (i *Instance) PostForm(url string, data url.Values) (resp *http.Response, err error)

PostForm - wrapper for the Client.PostForm

Jump to

Keyboard shortcuts

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