aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-03-26 00:46:03 +0000
committerFuwn <[email protected]>2022-03-26 03:12:32 +0000
commitfdfc6c4123ecdb8d8e173a4661a0bcf7d7220a33 (patch)
tree447c5f99a973d9e69e5b3b490acad8c37e07b0c7 /examples
parentdocs(cargo): add meta (diff)
downloadwindmark-fdfc6c4123ecdb8d8e173a4661a0bcf7d7220a33.tar.xz
windmark-fdfc6c4123ecdb8d8e173a4661a0bcf7d7220a33.zip
feat: working proof
Forgot to commit this last night!
Diffstat (limited to 'examples')
-rw-r--r--examples/windmark.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/examples/windmark.rs b/examples/windmark.rs
new file mode 100644
index 0000000..7ce515f
--- /dev/null
+++ b/examples/windmark.rs
@@ -0,0 +1,58 @@
+// This file is part of Windmark <https://github.com/gemrest/windmark>.
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+// SPDX-License-Identifier: GPL-3.0-only
+
+#[macro_use]
+extern crate log;
+
+fn main() -> std::io::Result<()> {
+ windmark::Router::new()
+ .set_private_key_file("windmark_private.pem")
+ .set_certificate_chain_file("windmark_pair.pem")
+ .enable_default_logger(true)
+ .set_error_handler(|_| "error...".to_string())
+ .set_pre_route_callback(|stream| {
+ info!(
+ "accepted connection from {}",
+ stream.peer_addr().unwrap().ip()
+ )
+ })
+ .set_post_route_callback(|stream| {
+ info!(
+ "closed connection from {}",
+ stream.peer_addr().unwrap().ip()
+ )
+ })
+ .set_header(|_| "```\nART IS COOL\n```".to_string())
+ .set_footer(|_| "Copyright 2022".to_string())
+ .get("/", |_| {
+ "# INDEX\n\nWelcome!\n\n=> /test Test Page\n=> /time Unix Epoch\n"
+ .to_string()
+ })
+ .get("/ip", |stream| {
+ { format!("Hello, {}", stream.peer_addr().unwrap().ip()) }.into()
+ })
+ .get("/test", |_| "hi there\n=> / back".to_string())
+ .get("/time", |_| {
+ std::time::UNIX_EPOCH
+ .elapsed()
+ .unwrap()
+ .as_nanos()
+ .to_string()
+ })
+ .run()
+}