rest

package
v0.1.0-cvefix.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 10 * time.Second

DefaultTimeout - default REST timeout is 10 seconds.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// HealthCheckFn is the function set to test for health.
	// If not set the client will not keep track of health.
	// Calling this returns true or false if the target
	// is online or offline.
	HealthCheckFn func() bool

	// HealthCheckInterval will be the duration between re-connection attempts
	// when a call has failed with a network error.
	HealthCheckInterval time.Duration

	// HealthCheckTimeout determines timeout for each call.
	HealthCheckTimeout time.Duration

	// MaxErrResponseSize is the maximum expected response size.
	// Should only be modified before any calls are made.
	MaxErrResponseSize int64

	// ExpectTimeouts indicates if context timeouts are expected.
	// This will not mark the client offline in these cases.
	ExpectTimeouts bool
	// contains filtered or unexported fields
}

Client - http based RPC client.

func NewClient

func NewClient(url *url.URL, tr http.RoundTripper, newAuthToken func(aud string) string) *Client

NewClient - returns new REST client.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, values url.Values, body io.Reader, length int64) (reply io.ReadCloser, err error)

Call - make a REST call with context.

func (*Client) Close

func (c *Client) Close()

Close closes all idle connections of the underlying http client

func (*Client) IsOnline

func (c *Client) IsOnline() bool

IsOnline returns whether the client is likely to be online.

func (*Client) MarkOffline

func (c *Client) MarkOffline() bool

MarkOffline - will mark a client as being offline and spawns a goroutine that will attempt to reconnect if HealthCheckFn is set. returns true if the node changed state from online to offline

type NetworkError

type NetworkError struct {
	Err error
}

NetworkError - error type in case of errors related to http/transport for ex. connection refused, connection reset, dns resolution failure etc. All errors returned by storage-rest-server (ex errFileNotFound, errDiskNotFound) are not considered to be network errors.

func (*NetworkError) Error

func (n *NetworkError) Error() string

func (*NetworkError) Unwrap

func (n *NetworkError) Unwrap() error

Unwrap returns the error wrapped in NetworkError.

Jump to

Keyboard shortcuts

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