aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-03 02:44:25 +0000
committerFuwn <[email protected]>2023-04-03 02:44:25 +0000
commited52d304178d5d37a0af710f06e8fe8eb65b2c24 (patch)
treea1ce35c6a54d576361a6378c3cf59ea60ebc15e1 /examples
parentfeat(response): allow multiple languages (diff)
downloadwindmark-ed52d304178d5d37a0af710f06e8fe8eb65b2c24.tar.xz
windmark-ed52d304178d5d37a0af710f06e8fe8eb65b2c24.zip
feat(router): GET RID OF DIRTY BOXES
Diffstat (limited to 'examples')
-rw-r--r--examples/windmark.rs86
1 files changed, 37 insertions, 49 deletions
diff --git a/examples/windmark.rs b/examples/windmark.rs
index 50914f4..c139b55 100644
--- a/examples/windmark.rs
+++ b/examples/windmark.rs
@@ -23,7 +23,7 @@ extern crate log;
use windmark::{
response::Response,
- returnable::CallbackContext,
+ returnable::{CallbackContext, RouteContext},
success,
Router,
};
@@ -102,14 +102,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
"/",
success!("# INDEX\n\nWelcome!\n\n=> /test Test Page\n=> /time Unix Epoch"),
);
- router.mount(
- "/specific-mime",
- Box::new(|_| {
- Response::success("hi".to_string())
- .with_mime("text/plain")
- .clone()
- }),
- );
+ router.mount("/specific-mime", |_| {
+ Response::success("hi".to_string())
+ .with_mime("text/plain")
+ .clone()
+ });
router.mount(
"/ip",
success!(
@@ -154,26 +151,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
),
);
- router.mount(
- "/input",
- Box::new(|context| {
- if let Some(name) = context.url.query() {
- Response::success(format!("Your name is {}!", name))
- } else {
- Response::input("What is your name?")
- }
- }),
- );
- router.mount(
- "/sensitive-input",
- Box::new(|context| {
- if let Some(password) = context.url.query() {
- Response::success(format!("Your password is {}!", password))
- } else {
- Response::sensitive_input("What is your password?")
- }
- }),
- );
+ router.mount("/input", |context: RouteContext| {
+ if let Some(name) = context.url.query() {
+ Response::success(format!("Your name is {}!", name))
+ } else {
+ Response::input("What is your name?")
+ }
+ });
+ router.mount("/sensitive-input", |context: RouteContext| {
+ if let Some(password) = context.url.query() {
+ Response::success(format!("Your password is {}!", password))
+ } else {
+ Response::sensitive_input("What is your password?")
+ }
+ });
router.mount("/error", windmark::certificate_not_valid!("no"));
router.mount(
"/redirect",
@@ -189,26 +180,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
router.mount("/string-file", {
windmark::binary_success!("hi", "text/plain")
});
- router.mount(
- "/secret",
- Box::new(|context| {
- if let Some(certificate) = context.certificate {
- Response::success(format!("Your public key: {}.", {
- (|| -> Result<String, openssl::error::ErrorStack> {
- Ok(format!(
- "{:?}",
- certificate.public_key()?.rsa()?.public_key_to_pem()?
- ))
- })()
- .unwrap_or_else(|_| "Unknown".to_string())
- },))
- } else {
- Response::client_certificate_required(
- "This is a secret route! Identify yourself!",
- )
- }
- }),
- );
+ router.mount("/secret", |context: RouteContext| {
+ if let Some(certificate) = context.certificate {
+ Response::success(format!("Your public key: {}.", {
+ (|| -> Result<String, openssl::error::ErrorStack> {
+ Ok(format!(
+ "{:?}",
+ certificate.public_key()?.rsa()?.public_key_to_pem()?
+ ))
+ })()
+ .unwrap_or_else(|_| "Unknown".to_string())
+ },))
+ } else {
+ Response::client_certificate_required(
+ "This is a secret route! Identify yourself!",
+ )
+ }
+ });
router.run().await
}