http

package
v0.0.0-...-1bfa4a9 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClientTimeout = 5 * time.Second

DefaultClientTimeout is the recommended timeout for the client.

View Source
var DefaultRetryOptions = RetryOptions{
	Base:   time.Second,
	Max:    5 * time.Second,
	Factor: 0.2,
}

DefaultRetryOptions are the recommended retry settings.

Functions

This section is empty.

Types

type Client

type Client struct {
	*http.Client
}

Client is a http.Client with a fixed timeout.

func NewClient

func NewClient(timeout time.Duration) Client

NewClient returns a new client with the given timeout.

func (Client) SendRequest

func (c Client) SendRequest(ctx context.Context, url string, request jsonrpc.Request, options *RetryOptions) (jsonrpc.Response, error)

SendRequest sends the `jsonrpc.Request` to the given URL. It only retries sending the request if the retry options are non-nil. Otherwise it returns the response and error immediately.

type RequestWithResponder

type RequestWithResponder struct {
	Context   context.Context
	ID        interface{}
	Method    string
	Params    interface{}
	Responder chan jsonrpc.Response
	Query     url.Values
}

func NewRequestWithResponder

func NewRequestWithResponder(ctx context.Context, id interface{}, method string, params interface{}, query url.Values) RequestWithResponder

NewRequestWithResponder constructs a new SubmitTx request wrapper object.

func (RequestWithResponder) IsMessage

func (RequestWithResponder) IsMessage()

IsMessage implements the `phi.Message` interface.

func (RequestWithResponder) RespondWithErr

func (req RequestWithResponder) RespondWithErr(code int, err error)

type RetryOptions

type RetryOptions struct {
	Base   time.Duration // Time interval before first retry.
	Max    time.Duration // Maximum time interval between two retries.
	Factor float64       // next_interval = previous_interval * (1 + factor)
}

RetryOptions are used for retrying failed requests sent using the client.

Jump to

Keyboard shortcuts

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