Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn info(&self) -> PluginInfo;
    fn execute<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        context: &'life1 HttpContext,
        config: &'life2 Value,
    ) -> Pin<Box<dyn Future<Output = Result<Value, PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

插件定义

  • name

插件的名称,原则上不要重复。在PluginManager中,如果重复了,后添加的将被覆盖。

  • execute

execute接收HttpContext参数,该HttpContext是可变的(内部可变性),可在插件逻辑内部修改请求和响应。 注意:当多个插件修改HttpContext的同一个属性时,后执行的插件会覆盖前一个插件的修改。 插件实现方应该自行决定插件运行阶段(请求阶段或者响应阶段),从而获取或修改request或response的数据。

  • 返回值 返回[serde_json:Value]

Required Methods§

Source

fn name(&self) -> &str

插件名称

Source

fn info(&self) -> PluginInfo

插件信息

Source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, context: &'life1 HttpContext, config: &'life2 Value, ) -> Pin<Box<dyn Future<Output = Result<Value, PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

执行插件

Trait Implementations§

Source§

impl TryFrom<PathBuf> for Box<dyn Plugin>

Source§

type Error = PluginError

The type returned in the event of a conversion error.
Source§

fn try_from(value: PathBuf) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Vec<u8>> for Box<dyn Plugin>

Source§

type Error = PluginError

The type returned in the event of a conversion error.
Source§

fn try_from(from: Vec<u8>) -> Result<Box<dyn Plugin>, Self::Error>

Performs the conversion.

Implementors§