rpcx

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error
	Close() error
}

Client defines interface for a client to make contextual remote calls.

type ClientMock

type ClientMock struct {
	// CallFunc mocks the Call method.
	CallFunc func(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error

	// CloseFunc mocks the Close method.
	CloseFunc func() error
	// contains filtered or unexported fields
}

ClientMock is a mock implementation of Client.

func TestSomethingThatUsesClient(t *testing.T) {

	// make and configure a mocked Client
	mockedClient := &ClientMock{
		CallFunc: func(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error {
			panic("mock out the Call method")
		},
		CloseFunc: func() error {
			panic("mock out the Close method")
		},
	}

	// use mockedClient in code that requires Client
	// and then make assertions.

}

func (*ClientMock) Call

func (mock *ClientMock) Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error

Call calls CallFunc.

func (*ClientMock) CallCalls

func (mock *ClientMock) CallCalls() []struct {
	Ctx           context.Context
	ServiceMethod string
	Args          interface{}
	Reply         interface{}
}

CallCalls gets all the calls that were made to Call. Check the length with:

len(mockedClient.CallCalls())

func (*ClientMock) Close

func (mock *ClientMock) Close() error

Close calls CloseFunc.

func (*ClientMock) CloseCalls

func (mock *ClientMock) CloseCalls() []struct {
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedClient.CloseCalls())

type Dialer

type Dialer interface {
	Dial(network, address string) (RPCClient, error)
}

Dialer is a maker interface dialing to rpc server and returning new Client

func JSONRPC

func JSONRPC() Dialer

JSONRPC returns the jsonrpc.Dial dialer.

type DialerFunc

type DialerFunc func(network, address string) (RPCClient, error)

DialerFunc is an adapter to use ordinary functions as Dialer.

func (DialerFunc) Dial

func (f DialerFunc) Dial(network, addr string) (RPCClient, error)

Dial calls the wrapped function.

type RPCClient

type RPCClient interface {
	Call(serviceMethod string, args interface{}, reply interface{}) error
	Close() error
}

RPCClient describes a pure standard library rpc client.

type Redialer

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

Redialer redials the RPC server with the provided repeating strategy, in case if Call has been failed.

func NewRedialer

func NewRedialer(dialer Dialer, strtg strategy.Interface, network, addr string) (*Redialer, error)

NewRedialer makes new instance of Redialer.

func (*Redialer) Call

func (r *Redialer) Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error

Call makes a call to the remote RPC server, tries to redial if the RPC connection is shut down.

func (*Redialer) Close

func (r *Redialer) Close() error

Close proxies the Close call to the embedded rpc client.

Jump to

Keyboard shortcuts

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