http

package
v10.0.0-...-063e449 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAvailableHost = fmt.Errorf("no host available to perform the request")

ErrNoAvailableHost indicates that the client could not find an available host to send the request to.

View Source
var ErrTooManyRedirects = fmt.Errorf("maximum leader redirect limit exceeded")

ErrTooManyRedirects indicates that the client exceeded the maximum number of redirects

Functions

func ParseHostEnv

func ParseHostEnv(varName string) (protocol, host string, port uint16, err error)

ParseHostEnv parses a host URL from an environment variable and extracts its components. It returns the protocol scheme, hostname, port number, or any parsing error encountered.

Types

type Client

type Client struct {
	*http.Client

	Prefix string
	// contains filtered or unexported fields
}

Client is a wrapper around stock `http.Client` that adds "retry on another host" behaviour based on the supplied configuration.

The client will fall back and try other nodes when the current node is unavailable, and would stop trying after exhausting the list of supplied hosts.

Note:

This type is not goroutine safe. A node is considered unavailable if the client is not reachable via the network. TODO: make the unavailability condition for the client more dynamic.

func NewClient

func NewClient(client *http.Client, hosts []string, configFuncs ...ConfigFunc) *Client

NewClient creates a default client that sends `execute` and query `requests` against the rqlited nodes supplied via `hosts` argument.

func (*Client) Delete

func (c *Client) Delete(u string, body io.Reader) (resp *http.Response, err error)

Delete sends DELETE requests to one of the hosts known to the client.

func (*Client) Execute

func (c *Client) Execute(url *url.URL, body io.Reader) (*http.Response, error)

Execute sends POST requests to one of the hosts known to the client

func (*Client) Get

func (c *Client) Get(u string) (resp *http.Response, err error)

Get sends GET requests to one of the hosts known to the client.

func (*Client) GetDirect

func (c *Client) GetDirect(u string) (resp *http.Response, err error)

GetDirect sends a GET request to the exact URL provided, with authentication but without host override or failover. Use this when you need to target a specific node rather than any node in the cluster.

func (*Client) Post

func (c *Client) Post(u string, body io.Reader) (resp *http.Response, err error)

Post sends POST requests to one of the hosts known to the client.

func (*Client) PostWithHeaders

func (c *Client) PostWithHeaders(u string, body io.Reader, headers http.Header) (resp *http.Response, err error)

PostWithHeaders sends POST requests with custom headers to one of the hosts known to the client.

func (*Client) Query

func (c *Client) Query(url *url.URL) (*http.Response, error)

Query sends GET requests to one of the hosts known to the client.

type ConfigFunc

type ConfigFunc func(*Client)

func WithBasicAuth

func WithBasicAuth(creds string) ConfigFunc

WithBasicAuth adds basic authentication behaviour to the client's request.

func WithLogger

func WithLogger(logger *log.Logger) ConfigFunc

WithLogger changes the default logger to the one provided.

func WithPrefix

func WithPrefix(prefix string) ConfigFunc

WithPrefix sets the prefix to be used when issuing HTTP requests against one of the rqlited nodes.

func WithScheme

func WithScheme(scheme string) ConfigFunc

WithScheme changes the default scheme used i.e "http".

type HostChangedError

type HostChangedError struct {
	NewHost string
}

HostChangedError indicates that the underlying request was executed on a different host different from the caller anticipated

func (*HostChangedError) Error

func (he *HostChangedError) Error() string

Jump to

Keyboard shortcuts

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