client

package
v0.0.0-...-fd63c1f Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeout   = &errTimeout{errors.New("timeout error")}
	ErrNetwork   = &errNetwork{errors.New("network error")}
	ErrPermanent = &errPermanent{errors.New("permanent error")}
)

Functions

func ErrorStatus

func ErrorStatus(err error) int

HTTP errors

func IsHttpError

func IsHttpError(err error) bool

func IsNetError

func IsNetError(err error) bool

func IsRetriableHttpError

func IsRetriableHttpError(err error) bool

func IsRetriableStatusCode

func IsRetriableStatusCode(c int) bool

func WrapError

func WrapError(e error, t ErrorWrapper) error

func WrapNetError

func WrapNetError(err error) error

Types

type Client

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

Client manages communication with a Tezos RPC server.

func New

func New() *Client

func (*Client) Connect

func (c *Client) Connect(base string) error

func (*Client) Do

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

Do retrieves values from the API and marshals them into the provided interface.

func (*Client) Get

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

func (*Client) GetJson

func (c *Client) GetJson(ctx context.Context, urlpath string, result any) error

func (*Client) NewJsonResponseDecoder

func (c *Client) NewJsonResponseDecoder(v any) ResponseHandler

func (*Client) NewRawResponseDecoder

func (c *Client) NewRawResponseDecoder(v *bytes.Buffer) ResponseHandler

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, urlStr, mediaType string, body any) (*http.Request, error)

func (*Client) PostJson

func (c *Client) PostJson(ctx context.Context, urlpath string, body, result any) error

func (*Client) SetLogLevel

func (c *Client) SetLogLevel(lvl log.Level)

func (*Client) WithApiKey

func (c *Client) WithApiKey(k string) *Client

func (*Client) WithHttpClient

func (c *Client) WithHttpClient(hc *http.Client) *Client

func (*Client) WithLogger

func (c *Client) WithLogger(log log.Logger) *Client

func (*Client) WithRetry

func (c *Client) WithRetry(num int, delay time.Duration) *Client

func (*Client) WithUserAgent

func (c *Client) WithUserAgent(s string) *Client

type ErrorWrapper

type ErrorWrapper interface {
	Wrap(error) error
}

type HTTPError

type HTTPError interface {
	error
	HTTPStatus
	Body() []byte
}

HTTPError retains HTTP status and error response body

type HTTPStatus

type HTTPStatus interface {
	Request() string // e.g. GET /...
	Status() string  // e.g. "200 OK"
	StatusCode() int // e.g. 200
}

HTTPStatus interface represents an unprocessed HTTP reply

type ResponseHandler

type ResponseHandler func(context.Context, *http.Response) error

Jump to

Keyboard shortcuts

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