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