36 个版本

0.3.11 2024年7月17日
0.3.9 2023年5月5日
0.2.5 2023年3月31日
0.1.20 2022年7月31日
0.1.7 2022年3月31日

#224 in 网页编程

Download history 265/week @ 2024-04-27 161/week @ 2024-06-22 6/week @ 2024-06-29 125/week @ 2024-07-13 15/week @ 2024-07-20 7/week @ 2024-07-27 11/week @ 2024-08-03 94/week @ 2024-08-10

每月下载 135
用于 3 crates

GPL-3.0-only

63KB
974

Windmark

crates.io docs.rs github.com

Windmark 是一个优雅且高性能的异步 Gemini 服务器框架,适用于现代时代!

现在支持 Tokioasync-std

用法

Windmark 正在开发一个基于宏的 "struct-router"。目前可以通过它使用 Windmark 的一些功能子集。有关更多信息,请查看 Rossweisse

特性

特性 描述
default 使用 Tokio 的基本 Windmark 框架
logger 启用默认的 pretty_env_logger 集成
auto-deduce-mime 公开 Response 和宏,自动填充非 Gemini 响应的 MIME
response-macros 所有 Response 的简单宏
tokio Tokio 标记为异步运行时
async-std async-std 标记为异步运行时
prelude 公开包含最常用 Windmark 特性的 prelude 模块

添加 Windmark 和 Tokio 作为依赖项

# Cargo.toml

[dependencies]
windmark = "0.3.9"
tokio = { version = "1.26.0", features = ["full"] }

# If you would like to use the built-in logger (recommended)
# windmark = { version = "0.3.9", features = ["logger"] }

# If you would like to use the built-in MIME dedection when `Success`-ing a file
# (recommended)
# windmark = { version = "0.3.9", features = ["auto-deduce-mime"] }

# If you would like to use macro-based responses (as seen below)
# windmark = { version = "0.3.9", features = ["response-macros"] }

实现 Windmark 服务器

// src/main.rs

// ...

#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  windmark::router::Router::new()
    .set_private_key_file("windmark_private.pem")
    .set_certificate_file("windmark_public.pem")
    .mount("/", windmark::success!("Hello, World!"))
    .set_error_handler(|_|
      windmark::response::Response::permanent_failure("This route does not exist!")
    )
    .run()
    .await
}

使用 Rossweisse 实现 Windmark 服务器

// src/main.rs

// ...

#[rossweisse::router]
struct Router;

#[rossweisse::router]
impl Router {
  #[route(index)]
  pub fn index(
    _context: windmark::context::RouteContext,
  ) -> Response {
    Response::success("Hello, World!")
  }
}

// ...

示例

示例可以在 examples/ 目录中找到,其中包含每个示例的目的和有用信息。

使用 Windmark 编写的功能齐全的 Gemini 纽带的示例可以在 这里 找到。此示例 Gemini 纽带也是 Fuwn(此库的作者)个人 Gemini 纽带的源代码!

模块

模块是可以重用的扩展,可以按程序方式附加到 Windmark 路由器上。

添加您的模块!

使用 Windmark 的胶囊

添加您的模块!

许可证

此项目使用 GNU 通用公共许可证 v3.0 许可。

依赖项

约 5-19MB
~277K SLoC