rpc

package
v0.0.0-...-3aa76b9 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedContentType = errors.New("unsupported content type")
)

Common errors

Functions

func DecodeJSON

func DecodeJSON(res *http.Response, v interface{}) error

DecodeJSON decodes a json response body into a value reciever.

func DecodeText

func DecodeText(res *http.Response) (string, error)

DecodeText decodes a text/plain response body and returns it as a string.

func HasStatus

func HasStatus(err error, status int) bool

HasStatus check if an error is a HTTPError with the specified status.

Types

type Client

type Client interface {
	CreateRequest(method, url string, body interface{}) (*http.Request, error)
	Do(req *http.Request) (*http.Response, error)
}

Client rpc client interface for creating and executing requrests.

func NewClient

func NewClient(timeout time.Duration) Client

NewClient creates a new rpc client using the default implementation.

type MockClient

type MockClient struct {
	Client
	Responses MockResponses
}

MockClient mock implementation of a client.

func (*MockClient) Do

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

Do perform a mked request.

type MockResponse

type MockResponse struct {
	Body interface{}
	Err  error
}

MockResponse mocked rpc response.

type MockResponses

type MockResponses map[string]MockResponse

MockResponses is a MockResponse map

Jump to

Keyboard shortcuts

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