Documentation
¶
Index ¶
- Variables
- func ParseHostEnv(varName string) (protocol, host string, port uint16, err error)
- type Client
- func (c *Client) Delete(u string, body io.Reader) (resp *http.Response, err error)
- func (c *Client) Execute(url *url.URL, body io.Reader) (*http.Response, error)
- func (c *Client) Get(u string) (resp *http.Response, err error)
- func (c *Client) GetDirect(u string) (resp *http.Response, err error)
- func (c *Client) Post(u string, body io.Reader) (resp *http.Response, err error)
- func (c *Client) PostWithHeaders(u string, body io.Reader, headers http.Header) (resp *http.Response, err error)
- func (c *Client) Query(url *url.URL) (*http.Response, error)
- type ConfigFunc
- type HostChangedError
Constants ¶
This section is empty.
Variables ¶
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.
var ErrTooManyRedirects = fmt.Errorf("maximum leader redirect limit exceeded")
ErrTooManyRedirects indicates that the client exceeded the maximum number of redirects
Functions ¶
Types ¶
type Client ¶
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) GetDirect ¶
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.
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