request

package
v1.10.57 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Client *http.Client

Client stores a HTTP client, so that it doesn't need to be initialised on every request

View Source
var HTTPNewRequest = http.NewRequest

HTTPNewRequest stores http.NewRequest, which can be substituted in unit tests

View Source
var MakeRequest = func(method string, url string, headers map[string]string, body []byte) (*http.Response, error) {
	var (
		response *http.Response
		count    int = 0
	)

	request, err := HTTPNewRequest(method, url, bytes.NewBuffer(body))
	if err != nil {
		return nil, err
	}

	for k, v := range headers {
		request.Header.Set(k, v)
	}

	for count == 0 || (err != nil && count < 3) {

		response, err = Client.Do(request)
		count++
	}
	if err != nil {
		return nil, err
	}

	if response.StatusCode >= 400 {
		err = errors.New(strconv.Itoa(response.StatusCode))

		return nil, err
	}

	return response, err
}

MakeRequest builds an authenticated HTTP client which sends HTTP requests and parses the responses

Functions

func InitialiseClient

func InitialiseClient() (*http.Client, error)

InitialiseClient sets up an HTTP client and returns it

Types

This section is empty.

Jump to

Keyboard shortcuts

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