Documentation ¶
Index ¶
- Constants
- func CastToPrimitiveTypes(args map[string]interface{}) map[string]interface{}
- func NewCommand(cmd string, args []string, env []string) *exec.Cmd
- func SHA256SUM(filename string) (string, *gerr.GatewayDError)
- func Verify(params, returnVal *structpb.Struct) bool
- type IHook
- type IPlugin
- type IRegistry
- type Identifier
- type Method
- type Plugin
- type Priority
- type Registry
- func (reg *Registry) Add(plugin *Plugin) bool
- func (reg *Registry) AddHook(hookName string, priority Priority, hookMethod Method)
- func (reg *Registry) Exists(name, version, remoteURL string) bool
- func (reg *Registry) ForEach(f func(Identifier, *Plugin))
- func (reg *Registry) Get(id Identifier) *Plugin
- func (reg *Registry) Hooks() map[string]map[Priority]Method
- func (reg *Registry) List() []Identifier
- func (reg *Registry) LoadPlugins(plugins []config.Plugin)
- func (reg *Registry) RegisterHooks(id Identifier)
- func (reg *Registry) Remove(id Identifier)
- func (reg *Registry) Run(ctx context.Context, args map[string]interface{}, hookName string, ...) (map[string]interface{}, *gerr.GatewayDError)
- func (reg *Registry) Shutdown()
Constants ¶
const ( // Run command hooks (cmd/run.go). OnConfigLoaded string = "onConfigLoaded" OnNewLogger string = "onNewLogger" OnNewPool string = "onNewPool" OnNewClient string = "onNewClient" OnNewProxy string = "onNewProxy" OnNewServer string = "onNewServer" OnSignal string = "onSignal" // Server hooks (network/server.go). OnRun string = "onRun" OnBooting string = "onBooting" OnBooted string = "onBooted" OnOpening string = "onOpening" OnOpened string = "onOpened" OnClosing string = "onClosing" OnClosed string = "onClosed" OnTraffic string = "onTraffic" OnShutdown string = "onShutdown" OnTick string = "onTick" // Proxy hooks (network/proxy.go). OnTrafficFromClient string = "onTrafficFromClient" OnTrafficToServer string = "onTrafficToServer" OnTrafficFromServer string = "onTrafficFromServer" OnTrafficToClient string = "onTrafficToClient" )
Variables ¶
This section is empty.
Functions ¶
func CastToPrimitiveTypes ¶ added in v0.2.4
CastToPrimitiveTypes casts the values of a map to its primitive type (e.g. time.Duration to float64) to prevent structpb invalid type(s) errors.
func NewCommand ¶ added in v0.2.0
NewCommand returns a command with the given arguments and environment variables.
func SHA256SUM ¶ added in v0.2.4
func SHA256SUM(filename string) (string, *gerr.GatewayDError)
SHA256SUM returns the sha256 checksum of a file. Ref: https://github.com/codingsince1985/checksum A little copying is better than a little dependency.
Types ¶
type IPlugin ¶ added in v0.2.2
type IPlugin interface { Start() (net.Addr, error) Stop() Dispense() (pluginV1.GatewayDPluginServiceClient, *gerr.GatewayDError) }
type IRegistry ¶ added in v0.2.4
type IRegistry interface { // Plugin management Add(plugin *Plugin) bool Get(id Identifier) *Plugin List() []Identifier Exists(name, version, remoteURL string) bool ForEach(f func(Identifier, *Plugin)) Remove(id Identifier) Shutdown() LoadPlugins(plugins []config.Plugin) RegisterHooks(id Identifier) // Hook management IHook }
type Identifier ¶ added in v0.0.8
type Plugin ¶ added in v0.0.8
type Plugin struct { goplugin.NetRPCUnsupportedPlugin pluginV1.GatewayDPluginServiceServer ID Identifier Description string Authors []string License string ProjectURL string LocalPath string Args []string Env []string Enabled bool // internal and external config options Config map[string]string // hooks it attaches to Hooks []string 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 (*Plugin) Dispense ¶ added in v0.0.8
func (p *Plugin) Dispense() (pluginV1.GatewayDPluginServiceClient, *gerr.GatewayDError)
Dispense returns the plugin client.
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 struct { Logger zerolog.Logger Compatibility config.CompatibilityPolicy Verification config.VerificationPolicy Acceptance config.AcceptancePolicy // contains filtered or unexported fields }
func NewRegistry ¶ added in v0.0.8
func NewRegistry( compatibility config.CompatibilityPolicy, verification config.VerificationPolicy, acceptance config.AcceptancePolicy, logger zerolog.Logger, ) *Registry
NewRegistry creates a new plugin registry.
func (*Registry) ForEach ¶ added in v0.3.0
func (reg *Registry) ForEach(f func(Identifier, *Plugin))
ForEach iterates over all plugins in the registry.
func (*Registry) Get ¶ added in v0.0.8
func (reg *Registry) Get(id Identifier) *Plugin
Get returns a plugin from the registry.
func (*Registry) List ¶ added in v0.0.8
func (reg *Registry) List() []Identifier
List returns a list of all plugins in the registry.
func (*Registry) LoadPlugins ¶ added in v0.0.8
LoadPlugins loads plugins from the config file.
func (*Registry) RegisterHooks ¶ added in v0.0.8
func (reg *Registry) RegisterHooks(id Identifier)
RegisterHooks registers the hooks for the given plugin.
func (*Registry) Remove ¶ added in v0.0.8
func (reg *Registry) Remove(id Identifier)
Remove removes a plugin from the registry.
func (*Registry) Run ¶ added in v0.2.4
func (reg *Registry) Run( ctx context.Context, args map[string]interface{}, hookName string, 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 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.