Skip to main content

ModuleLoader

Trait ModuleLoader 

Source
pub trait ModuleLoader: Send + Sync {
    // Required method
    fn name(&self) -> &str;

    // Provided methods
    fn validate_config(
        &self,
        config: &HashMap<String, String>,
    ) -> ModuleResult<()> { ... }
    fn create_middleware(
        &self,
        config: &HashMap<String, String>,
    ) -> ModuleResult<Option<Arc<dyn Handler>>> { ... }
    fn create_handler(
        &self,
        config: &HashMap<String, String>,
    ) -> ModuleResult<Option<Arc<dyn Handler>>> { ... }
    fn on_load(&self) -> ModuleResult<()> { ... }
    fn on_unload(&self) -> ModuleResult<()> { ... }
    fn on_reload(&self, config: &HashMap<String, String>) -> ModuleResult<()> { ... }
}
Expand description

A module loader creates module instances from configuration.

Implement this trait to add custom functionality to gatel. Each loader is responsible for a named directive (e.g., “my-custom-middleware”) and creates Module instances when that directive appears in the config.

Required Methods§

Source

fn name(&self) -> &str

The directive name that triggers this module (e.g., “waf”, “graphql”).

Provided Methods§

Source

fn validate_config(&self, config: &HashMap<String, String>) -> ModuleResult<()>

Validate the configuration for this module. Called during config parsing before the server starts. Return Ok(()) if the config is valid, or an error describing the issue.

Source

fn create_middleware( &self, config: &HashMap<String, String>, ) -> ModuleResult<Option<Arc<dyn Handler>>>

Create a middleware instance from the given configuration. Return None if this module does not provide middleware.

Source

fn create_handler( &self, config: &HashMap<String, String>, ) -> ModuleResult<Option<Arc<dyn Handler>>>

Create a handler instance from the given configuration. Return None if this module does not provide a terminal handler.

Source

fn on_load(&self) -> ModuleResult<()>

Called once when the module is loaded (server startup).

Source

fn on_unload(&self) -> ModuleResult<()>

Called when the server is shutting down.

Source

fn on_reload(&self, config: &HashMap<String, String>) -> ModuleResult<()>

Called when configuration is reloaded (hot-reload).

Implementors§