client

package
v0.0.0-...-03d24db Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HTTPGET is the method string used for calling Request()
	HTTPGET = http.MethodGet
	// HTTPPOST is the method string used for calling Request()
	HTTPPOST = http.MethodPost
	// HTTPDELETE is the method string used for calling
	HTTPDELETE = http.MethodDelete

	// DefaultRetries this enables Request() to handle the situation where the server connection fails
	DefaultRetries = 3
	// DefaultTimeout is the default timeout for the HTTP client
	DefaultTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPclient

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

HTTPclient is the Vocdoni API HTTP client.

func New

func New(host string) (*HTTPclient, error)

New connects to the API host with a random bearer token and returns the handle

func (*HTTPclient) Request

func (c *HTTPclient) Request(method string, jsonBody any, params []string, urlPath ...string) ([]byte, int, error)

Request performs a `method` type raw request to the endpoint specified in urlPath parameter. Method is either GET or POST. If POST, a JSON struct should be attached. Returns the response, the status code and an error.

Supports query parameters via `params` slice. If the slice is not empty, it should contain pairs of strings; the first element of each pair is the key, and the second element is the value.

func (*HTTPclient) SetHostAddr

func (c *HTTPclient) SetHostAddr(host *url.URL) error

SetHostAddr configures the host address of the API server.

func (*HTTPclient) SetRetries

func (c *HTTPclient) SetRetries(n int)

SetRetries configures the number of retries for the HTTP client.

func (*HTTPclient) SetTimeout

func (c *HTTPclient) SetTimeout(d time.Duration)

SetTimeout configures the timeout for the HTTP client.

Jump to

Keyboard shortcuts

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