🏗️ Elegant & Highly Performant Async Gemini Server Framework for the Modern Age
async
framework
gemini-protocol
protocol
gemini
rust
1//! `cargo run --example stateful_module --features response-macros`
2
3use windmark::{context::HookContext, router::Router};
4
5#[derive(Default)]
6struct Clicker {
7 clicks: usize,
8}
9
10impl windmark::module::Module for Clicker {
11 fn on_attach(&mut self, _router: &mut Router) {
12 println!("module 'clicker' has been attached!");
13 }
14
15 fn on_pre_route(&mut self, context: HookContext) {
16 self.clicks += 1;
17
18 println!(
19 "module 'clicker' has been called before the route '{}' with {} clicks!",
20 context.url.path(),
21 self.clicks,
22 );
23 }
24
25 fn on_post_route(&mut self, context: HookContext) {
26 println!(
27 "module 'clicker' clicker has been called after the route '{}' with {} \
28 clicks!",
29 context.url.path(),
30 self.clicks,
31 );
32 }
33}
34
35#[windmark::main]
36async fn main() -> Result<(), Box<dyn std::error::Error>> {
37 let mut router = Router::new();
38
39 router.set_private_key_file("windmark_private.pem");
40 router.set_certificate_file("windmark_public.pem");
41 #[cfg(feature = "logger")]
42 {
43 router.enable_default_logger(true);
44 }
45 router.attach(Clicker::default());
46 router.mount("/", windmark::success!("Hello!"));
47
48 router.run().await
49}