Plugin Location
All custom plugins should be added to the folder:pkg/plugins
, and be registered during initialization using the plugin manager.
Plugin Interface
To be recognized by TrustGate, every plugin must implement the following interface:Stage Lifecycle
Plugins can run at any of the following stages:pre_request
post_request
pre_response
post_response
Stages()
method, or validate supported stages using the AllowedStages()
method.
Plugin Registration
To make your plugin available to TrustGate, you must register it inside the plugin manager. All plugin registrations happen in theManager
’s initializePlugins()
method, located in:
Plugin Configuration
Each plugin can be configured declaratively through the gateway configuration, a specific rule, or a consumer group. Below is an example of a plugin configuration block:-
name: The name of the plugin, as returned by its
Name()
method. - enabled: Whether the plugin should be active.
-
stage: The execution stage (
pre_request
,post_request
, etc.). - priority: Used when multiple plugins run sequentially; lower numbers run first.
- settings: Custom key-value pairs passed into the plugin for configuration and validation.
Example Plugin Skeleton
Tips for Writing Plugins
-
Always validate configuration using
ValidateConfig()
to avoid runtime errors. -
Use
PluginResponse
to control execution flow (continue
,reject
,halt
, etc.). - Plugins should be deterministic and fast — avoid long-running logic in the execution path.
- Consider writing unit tests for plugin logic in isolation.
- Avoid leaking sensitive data in logs unless explicitly masked or filtered.