client

package
v5.0.4-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: GPL-3.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConnectionIssue = errors.New("could not connect")

ErrConnectionIssue represents a connection problem.

View Source
var ErrInvalidNodeVersion = errors.New("invalid node version response")

ErrInvalidNodeVersion indicates that the /eth/v1/node/version API response format was not recognized.

View Source
var ErrMalformedHostname = errors.New("hostname must include port, separated by one colon, like example.com:3500")

ErrMalformedHostname is used to indicate if a host name's format is incorrect.

View Source
var ErrNotFound = errors.Wrap(ErrNotOK, "recv 404 NotFound response from API")

ErrNotFound specifically means that a '404 - NOT FOUND' response was received from the API.

View Source
var ErrNotOK = errors.New("did not receive 2xx response from API")

ErrNotOK is used to indicate when an HTTP request to the API failed with any non-2xx response code. More specific errors may be returned, but an error in reaction to a non-2xx response will always wrap ErrNotOK.

Functions

func Non200Err

func Non200Err(response *http.Response) error

Non200Err is a function that parses an HTTP response to handle responses that are not 200 with a formatted error.

Types

type Client

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

Client is a wrapper object around the HTTP client.

func NewClient

func NewClient(host string, opts ...ClientOpt) (*Client, error)

NewClient constructs a new client with the provided options (ex WithTimeout). `host` is the base host + port used to construct request urls. This value can be a URL string, or NewClient will assume an http endpoint if just `host:port` is used.

func (*Client) BaseURL

func (c *Client) BaseURL() *url.URL

BaseURL returns the base url of the client

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do execute the request against the http client

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, opts ...ReqOption) ([]byte, error)

Get is a generic, opinionated GET function to reduce boilerplate amongst the getters in this package.

func (*Client) NodeURL

func (c *Client) NodeURL() string

NodeURL returns a human-readable string representation of the beacon node base url.

func (*Client) Token

func (c *Client) Token() string

Token returns the bearer token used for jwt authentication

type ClientOpt

type ClientOpt func(*Client)

ClientOpt is a functional option for the Client type (http.Client wrapper)

func WithAuthenticationToken

func WithAuthenticationToken(token string) ClientOpt

WithAuthenticationToken sets an oauth token to be used.

func WithRoundTripper

func WithRoundTripper(t http.RoundTripper) ClientOpt

WithRoundTripper replaces the underlying HTTP's transport with a custom one.

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOpt

WithTimeout sets the .Timeout attribute of the wrapped http.Client.

type ReqOption

type ReqOption func(*http.Request)

ReqOption is a request functional option.

func WithAuthorizationToken

func WithAuthorizationToken(token string) ReqOption

WithAuthorizationToken is a request functional option that adds header for authorization token.

func WithSSZEncoding

func WithSSZEncoding() ReqOption

WithSSZEncoding is a request functional option that adds SSZ encoding header.

Directories

Path Synopsis
Package beacon provides a client for interacting with the standard Eth Beacon Node API.
Package beacon provides a client for interacting with the standard Eth Beacon Node API.

Jump to

Keyboard shortcuts

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