plugin

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMinPort      uint   = 50000
	DefaultMaxPort      uint   = 60000
	PluginPriorityStart uint   = 1000
	EmptyPoolCapacity   int    = 0
	LoggerName          string = "plugin"
)

Variables

This section is empty.

Functions

func Verify added in v0.0.8

func Verify(params, returnVal *structpb.Struct) bool

Verify compares two structs and returns true if they are equal.

Types

type HookConfig added in v0.0.8

type HookConfig struct {
	Logger       zerolog.Logger
	Verification Policy
	// contains filtered or unexported fields
}

func NewHookConfig added in v0.0.8

func NewHookConfig() *HookConfig

NewHookConfig returns a new HookConfig.

func (*HookConfig) Add added in v0.0.8

func (h *HookConfig) Add(hookType HookType, prio Priority, hook HookDef)

Add adds a hook with a priority to the hooks map.

func (*HookConfig) Get added in v0.0.8

func (h *HookConfig) Get(hookType HookType) map[Priority]HookDef

Get returns the hooks of a specific type.

func (*HookConfig) Hooks added in v0.0.8

func (h *HookConfig) Hooks() map[HookType]map[Priority]HookDef

Hooks returns the hooks.

func (*HookConfig) Run added in v0.0.8

func (h *HookConfig) Run(
	ctx context.Context,
	args map[string]interface{},
	hookType HookType,
	verification Policy,
	opts ...grpc.CallOption,
) (map[string]interface{}, *gerr.GatewayDError)

Run runs the hooks of a specific type. The result of the previous hook is passed to the next hook as the argument, aka. chained. The context is passed to the hooks as well to allow them to cancel the execution. The args are passed to the first hook as the argument. The result of the first hook is passed to the second hook, and so on. The result of the last hook is eventually returned. The verification mode is used to determine how to handle errors. If the verification mode is set to Abort, the execution is aborted on the first error. If the verification mode is set to Remove, the hook is removed from the list of hooks on the first error. If the verification mode is set to Ignore, the error is ignored and the execution continues. If the verification mode is set to PassDown, the extra keys/values in the result are passed down to the next hook. The verification mode is set to PassDown by default. The opts are passed to the hooks as well to allow them to use the grpc.CallOption.

type HookDef added in v0.0.8

type HookType added in v0.0.8

type HookType string
const (
	// Run command hooks (cmd/run.go).
	OnConfigLoaded HookType = "onConfigLoaded"
	OnNewLogger    HookType = "onNewLogger"
	OnNewPool      HookType = "onNewPool"
	OnNewProxy     HookType = "onNewProxy"
	OnNewServer    HookType = "onNewServer"
	OnSignal       HookType = "onSignal"
	// Server hooks (network/server.go).
	OnRun            HookType = "onRun"
	OnBooting        HookType = "onBooting"
	OnBooted         HookType = "onBooted"
	OnOpening        HookType = "onOpening"
	OnOpened         HookType = "onOpened"
	OnClosing        HookType = "onClosing"
	OnClosed         HookType = "onClosed"
	OnTraffic        HookType = "onTraffic"
	OnIngressTraffic HookType = "onIngressTraffic"
	OnEgressTraffic  HookType = "onEgressTraffic"
	OnShutdown       HookType = "onShutdown"
	OnTick           HookType = "onTick"
	// Pool hooks (network/pool.go).
	OnNewClient HookType = "onNewClient"
)

type Identifier added in v0.0.8

type Identifier struct {
	Name      string
	Version   string
	RemoteURL string
	Checksum  string
}

type Impl added in v0.0.8

type Impl struct {
	goplugin.NetRPCUnsupportedPlugin
	pluginV1.GatewayDPluginServiceServer

	ID          Identifier
	Description string
	Authors     []string
	License     string
	ProjectURL  string
	LocalPath   string
	Enabled     bool
	// internal and external config options
	Config map[string]string
	// hooks it attaches to
	Hooks    []HookType
	Priority Priority
	// required plugins to be loaded before this one
	// Built-in plugins are always loaded first
	Requires   []Identifier
	Tags       []string
	Categories []string
	// contains filtered or unexported fields
}

func (*Impl) Dispense added in v0.0.8

Dispense returns the plugin client.

func (*Impl) Start added in v0.0.8

func (p *Impl) Start() (net.Addr, error)

Start starts the plugin.

func (*Impl) Stop added in v0.0.8

func (p *Impl) Stop()

Stop kills the plugin.

type Plugin added in v0.0.8

type Plugin interface {
	Start() (net.Addr, error)
	Stop()
	Dispense() (pluginV1.GatewayDPluginServiceClient, *gerr.GatewayDError)
}

type Policy added in v0.0.8

type Policy int
const (
	// Non-strict (permissive) mode.
	PassDown Policy = iota // Pass down the extra keys/values in result to the next plugins
	// Strict mode.
	Ignore // Ignore errors and continue
	Abort  // Abort on first error and return results
	Remove // Remove the hook from the list on error and continue
)

type Priority added in v0.0.8

type Priority uint

Priority is the priority of a hook. Smaller values are executed first (higher priority).

type Registry added in v0.0.8

type Registry interface {
	Add(plugin *Impl) bool
	Get(id Identifier) *Impl
	List() []Identifier
	Remove(id Identifier)
	Shutdown()
	LoadPlugins(pluginConfig *koanf.Koanf)
	RegisterHooks(id Identifier)
}

type RegistryImpl added in v0.0.8

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

func NewRegistry added in v0.0.8

func NewRegistry(hooksConfig *HookConfig) *RegistryImpl

NewRegistry creates a new plugin registry.

func (*RegistryImpl) Add added in v0.0.8

func (reg *RegistryImpl) Add(plugin *Impl) bool

Add adds a plugin to the registry.

func (*RegistryImpl) Get added in v0.0.8

func (reg *RegistryImpl) Get(id Identifier) *Impl

Get returns a plugin from the registry.

func (*RegistryImpl) List added in v0.0.8

func (reg *RegistryImpl) List() []Identifier

List returns a list of all plugins in the registry.

func (*RegistryImpl) LoadPlugins added in v0.0.8

func (reg *RegistryImpl) LoadPlugins(pluginConfig *koanf.Koanf)

LoadPlugins loads plugins from the config file.

func (*RegistryImpl) RegisterHooks added in v0.0.8

func (reg *RegistryImpl) RegisterHooks(id Identifier)

RegisterHooks registers the hooks for the given plugin.

func (*RegistryImpl) Remove added in v0.0.8

func (reg *RegistryImpl) Remove(id Identifier)

Remove removes a plugin from the registry.

func (*RegistryImpl) Shutdown added in v0.0.8

func (reg *RegistryImpl) Shutdown()

Shutdown shuts down all plugins in the registry.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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