Expand description
§Quick Start
- Create Plugin Project
[package]
name = "my-plugin"
version = "0.1.0"
edition = "2024"
[lib]
crate-type = ["cdylib"]
[dependencies]
aiway-plugin = "0.2.0"- 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);- Build Plugin
cargo build --releaseRe-exports§
pub use aiway_protocol as protocol;pub use log;pub use serde_json;
Macros§
Structs§
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Network
Plugin - 从指定的URL加载插件
- Plugin
Info - 插件信息
- Version
- SemVer version as defined by https://semver.org.