🏗️ Elegant & Highly Performant Async Gemini Server Framework for the Modern Age
async framework gemini-protocol protocol gemini rust
at main 35 lines 1.1 kB view raw
1//! `cargo run --example certificate --features response-macros` 2 3use windmark::response::Response; 4 5#[windmark::main] 6async fn main() -> Result<(), Box<dyn std::error::Error>> { 7 windmark::router::Router::new() 8 .set_private_key_file("windmark_private.pem") 9 .set_certificate_file("windmark_public.pem") 10 .mount("/secret", |context: windmark::context::RouteContext| { 11 if let Some(certificate) = context.certificate { 12 Response::success(format!("Your public key is '{}'.", { 13 (|| -> Result<String, openssl::error::ErrorStack> { 14 Ok(format!( 15 "{:?}", 16 certificate.public_key()?.rsa()?.public_key_to_pem()? 17 )) 18 })() 19 .unwrap_or_else(|_| { 20 "An error occurred while reading your public key.".to_string() 21 }) 22 })) 23 } else { 24 Response::client_certificate_required( 25 "This is a secret route ... Identify yourself!", 26 ) 27 } 28 }) 29 .mount( 30 "/invalid", 31 windmark::certificate_not_valid!("Your certificate is invalid."), 32 ) 33 .run() 34 .await 35}