Documentation
¶
Overview ¶
Package plugin provides support for RPC plugins with registration server. It also implements middleware calling all the registered and alive plugins
Index ¶
Constants ¶
const CtxMatch = conductorCtxtKey("match")
CtxMatch key used to retrieve matching request info from the request context
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conductor ¶
type Conductor struct {
Address string
RPCDialer RPCDialer
// contains filtered or unexported fields
}
Conductor accepts registrations from rpc plugins, keeps list of active/current plugins and provides middleware calling all of them.
func (*Conductor) Middleware ¶
Middleware hits all registered, alive-only plugins and modifies the original request accordingly. A plugin call error terminates the chain with HTTP 500. A reply status code >= 400 also stops the chain with that status, to allow plugins like auth which has to terminate the request in some cases.
type Handler ¶
type Handler struct {
Address string
Method string // full method name for rpc call, i.e. Plugin.Thing
Alive bool
// contains filtered or unexported fields
}
Handler contains information about a plugin's handler
type RPCClientMock ¶
type RPCClientMock struct {
// CallFunc mocks the Call method.
CallFunc func(serviceMethod string, args any, reply any) error
// contains filtered or unexported fields
}
RPCClientMock is a mock implementation of RPCClient.
func TestSomethingThatUsesRPCClient(t *testing.T) {
// make and configure a mocked RPCClient
mockedRPCClient := &RPCClientMock{
CallFunc: func(serviceMethod string, args any, reply any) error {
panic("mock out the Call method")
},
}
// use mockedRPCClient in code that requires RPCClient
// and then make assertions.
}
type RPCDialerFunc ¶
RPCDialerFunc is an adapter to allow the use of an ordinary functions as the RPCDialer.
type RPCDialerMock ¶
type RPCDialerMock struct {
// DialFunc mocks the Dial method.
DialFunc func(network string, address string) (RPCClient, error)
// contains filtered or unexported fields
}
RPCDialerMock is a mock implementation of RPCDialer.
func TestSomethingThatUsesRPCDialer(t *testing.T) {
// make and configure a mocked RPCDialer
mockedRPCDialer := &RPCDialerMock{
DialFunc: func(network string, address string) (RPCClient, error) {
panic("mock out the Dial method")
},
}
// use mockedRPCDialer in code that requires RPCDialer
// and then make assertions.
}
func (*RPCDialerMock) Dial ¶
func (mock *RPCDialerMock) Dial(network string, address string) (RPCClient, error)
Dial calls DialFunc.
func (*RPCDialerMock) DialCalls ¶
func (mock *RPCDialerMock) DialCalls() []struct { Network string Address string }
DialCalls gets all the calls that were made to Dial. Check the length with:
len(mockedRPCDialer.DialCalls())