5 个版本
0.1.1 | 2024年4月3日 |
---|---|
0.1.1-alpha.7 | 2024年2月23日 |
0.1.1-alpha.6 | 2024年2月22日 |
#2 in #kiwi
425 每月下载量
36KB
233 代码行
Kiwi SDK
此crate提供编写Kiwi插件的必要工具。
示例
拦截
//! A simple intercept hook that discards odd numbers from all counter sources
use kiwi_sdk::hook::intercept::{intercept, Action, Context, CounterEventCtx, EventCtx};
/// You must use the `#[intercept]` macro to define an intercept hook.
#[intercept]
fn handle(ctx: Context) -> Action {
match ctx.event {
// We only care about counter sources in this example
EventCtx::Counter(CounterEventCtx {
source_id: _,
count,
}) => {
if count % 2 == 0 {
// Returning `Action::Forward` instructs Kiwi to forward the event
// to the associated client.
return Action::Forward;
} else {
// Returning `Action::Discard` instructs Kiwi to discard the event,
// preventing it from reaching the associated client.
return Action::Discard;
}
}
_ => {}
}
Action::Forward
}
验证
//! A simple authenticate hook that allows all incoming HTTP requests
use kiwi_sdk::hook::authenticate::{authenticate, Outcome};
use kiwi_sdk::http::Request;
/// You must use the `#[authenticate]` macro to define an authenticate hook.
#[authenticate]
fn handle(req: Request<()>) -> Outcome {
// Returning `Outcome::Authenticate` instructs Kiwi to allow the connection to be established.
Outcome::Authenticate
}
依赖项
~2.5MB
~50K SLoC