plugin

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 10 Imported by: 0

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

View Source
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

func (c *Conductor) Middleware(next http.Handler) http.Handler

Middleware hits all registered, alive-only plugins and modifies the original request accordingly Failed plugin calls ignored. Status code from any plugin may stop the chain of calls if not 200. This is needed to allow plugins like auth which has to terminate request in some cases.

func (*Conductor) Run

func (c *Conductor) Run(ctx context.Context) error

Run creates and activates http registration server TODO: add some basic auth in case if exposed by accident

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 RPCClient

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

RPCClient defines interface for remote calls

type RPCClientMock

type RPCClientMock struct {
	// CallFunc mocks the Call method.
	CallFunc func(serviceMethod string, args interface{}, reply interface{}) 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 interface{}, reply interface{}) error {
			panic("mock out the Call method")
		},
	}

	// use mockedRPCClient in code that requires RPCClient
	// and then make assertions.

}

func (*RPCClientMock) Call

func (mock *RPCClientMock) Call(serviceMethod string, args interface{}, reply interface{}) error

Call calls CallFunc.

func (*RPCClientMock) CallCalls

func (mock *RPCClientMock) CallCalls() []struct {
	ServiceMethod string
	Args          interface{}
	Reply         interface{}
}

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

len(mockedRPCClient.CallCalls())

type RPCDialer

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

RPCDialer is a maker interface dialing to rpc server and returning new RPCClient

type RPCDialerFunc

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

RPCDialerFunc is an adapter to allow the use of an ordinary functions as the RPCDialer.

func (RPCDialerFunc) Dial

func (f RPCDialerFunc) Dial(network, address string) (RPCClient, error)

Dial rpc server

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())

Jump to

Keyboard shortcuts

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