Skip to main content

Crate aiway_plugin

Crate aiway_plugin 

Source
Expand description

§Quick Start

  1. Create Plugin Project
[package]
name = "my-plugin"
version = "0.1.0"
edition = "2024"

[lib]
crate-type = ["cdylib"]

[dependencies]
aiway-plugin = "0.2.0"
  1. Implement Plugin

In src/lib.rs:

use aiway_plugin::{async_trait, Plugin, PluginInfo, Version, protocol::context::HttpContext};
use aiway_plugin::protocol::context::http::request;
use serde_json::Value;
use bytes::Bytes;

pub struct MyPlugin;

#[async_trait]
impl Plugin for MyPlugin {
    fn name(&self) -> &str {
        "my-plugin"
    }

    fn info(&self) -> PluginInfo {
        PluginInfo {
            version: aiway_plugin::plugin_version!(),
            default_config: Value::Null,
            description: "My First AIWay Plugin".to_string(),
        }
    }

    async fn on_request(
        &self,
        config: &Value,
        head: &mut request::Parts,
        ctx: &mut HttpContext,
    ) -> Result<(), aiway_plugin::PluginError> {
        // Process the request here
        println!("MyPlugin: Received request {} {}", head.method, head.path);
        
        // Can modify request headers
        head.headers.insert("X-Custom-Header", "my-value".parse().unwrap());
        
        Ok(())
    }
}

// Export the plugin
aiway_plugin::export!(MyPlugin);
  1. Build Plugin
cargo build --release

Re-exports§

pub use aiway_protocol as protocol;
pub use log;
pub use serde_json;

Macros§

export
plugin_version

Structs§

Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.
NetworkPlugin
从指定的URL加载插件
PluginInfo
插件信息
Version
SemVer version as defined by https://semver.org.

Enums§

PluginError

Traits§

AsyncTryInto
Plugin

Attribute Macros§

async_trait