client

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const JSONRPCVersion = "2.0"

Variables

This section is empty.

Functions

func GetBody

func GetBody(body interface{}) (buf io.ReadWriter, err error)

func MakeBatches

func MakeBatches(elements []interface{}, batchSize int) (batches [][]interface{})

Types

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type HTTPError

type HTTPError struct {
	StatusCode int
	URL        url.URL
	Body       []byte
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

type HTTPErrorHandler

type HTTPErrorHandler func(res *http.Response, uri string) error

type Option

type Option func(request *Request) error

func ProxyOption

func ProxyOption(proxyURL string) Option

func TimeoutOption

func TimeoutOption(timeout time.Duration) Option

TimeoutOption is an option to set timeout for the http client calls value unit is nanoseconds

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*RPCError) Error

func (e *RPCError) Error() string

type RPCRequest

type RPCRequest struct {
	JSONRPC string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
	ID      int64       `json:"id,omitempty"`
}

type RPCRequestMapper

type RPCRequestMapper func(interface{}) RPCRequest

type RPCRequests

type RPCRequests []*RPCRequest

func MakeBatchRequests

func MakeBatchRequests(elements []interface{}, batchSize int, mapper RPCRequestMapper) (requests []RPCRequests)

type RPCResponse

type RPCResponse struct {
	JSONRPC string      `json:"jsonrpc"`
	Error   *RPCError   `json:"error,omitempty"`
	Result  interface{} `json:"result,omitempty"`
	ID      int64       `json:"id,omitempty"`
}

func (*RPCResponse) GetObject

func (r *RPCResponse) GetObject(toType interface{}) error

type RPCResponseRaw

type RPCResponseRaw struct {
	JSONRPC string          `json:"jsonrpc"`
	Error   *RPCError       `json:"error,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	ID      int64           `json:"id,omitempty"`
}

type Request

type Request struct {
	BaseURL          string
	Headers          map[string]string
	HTTPClient       HTTPClient
	HTTPErrorHandler HTTPErrorHandler
}

func InitClient

func InitClient(baseURL string, errorHandler HTTPErrorHandler, options ...Option) Request

func InitJSONClient

func InitJSONClient(baseURL string, errorHandler HTTPErrorHandler, options ...Option) Request

func (*Request) AddHeader

func (r *Request) AddHeader(key, value string)

func (*Request) Execute

func (r *Request) Execute(ctx context.Context, method, url string, body io.Reader, result interface{}) error

func (*Request) Get

func (r *Request) Get(result interface{}, path string, query url.Values) error

func (*Request) GetBase

func (r *Request) GetBase(path string) string

func (*Request) GetURL

func (r *Request) GetURL(path string, query url.Values) string

func (*Request) Post

func (r *Request) Post(result interface{}, path string, body interface{}) error

func (*Request) RPCBatchCall

func (r *Request) RPCBatchCall(requests RPCRequests) ([]RPCResponse, error)

func (*Request) RPCCall

func (r *Request) RPCCall(result interface{}, method string, params interface{}) error

func (*Request) RPCCallRaw

func (r *Request) RPCCallRaw(method string, params interface{}) ([]byte, error)

func (*Request) SetProxy

func (r *Request) SetProxy(proxyURL string) error

func (*Request) SetTimeout

func (r *Request) SetTimeout(timeout time.Duration)

Jump to

Keyboard shortcuts

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