Documentation ¶
Index ¶
- Constants
- func Verify(params, returnVal *structpb.Struct) bool
- type HookConfig
- func (h *HookConfig) Add(hookType HookType, prio Priority, hook HookDef)
- func (h *HookConfig) Get(hookType HookType) map[Priority]HookDef
- func (h *HookConfig) Hooks() map[HookType]map[Priority]HookDef
- func (h *HookConfig) Run(ctx context.Context, args map[string]interface{}, hookType HookType, ...) (map[string]interface{}, *gerr.GatewayDError)
- type HookDef
- type HookType
- type Identifier
- type Impl
- type Plugin
- type Policy
- type Priority
- type Registry
- type RegistryImpl
- func (reg *RegistryImpl) Add(plugin *Impl) bool
- func (reg *RegistryImpl) Get(id Identifier) *Impl
- func (reg *RegistryImpl) List() []Identifier
- func (reg *RegistryImpl) LoadPlugins(pluginConfig *koanf.Koanf)
- func (reg *RegistryImpl) RegisterHooks(id Identifier)
- func (reg *RegistryImpl) Remove(id Identifier)
- func (reg *RegistryImpl) Shutdown()
Constants ¶
Variables ¶
This section is empty.
Functions ¶
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 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 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
func (p *Impl) Dispense() (pluginV1.GatewayDPluginServiceClient, *gerr.GatewayDError)
Dispense returns the plugin client.
type Plugin ¶ added in v0.0.8
type Plugin interface { Start() (net.Addr, error) Stop() Dispense() (pluginV1.GatewayDPluginServiceClient, *gerr.GatewayDError) }
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.