···11+// This file is part of Windmark <https://github.com/gemrest/windmark>.
22+// Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
33+//
44+// This program is free software: you can redistribute it and/or modify
55+// it under the terms of the GNU General Public License as published by
66+// the Free Software Foundation, version 3.
77+//
88+// This program is distributed in the hope that it will be useful, but
99+// WITHOUT ANY WARRANTY; without even the implied warranty of
1010+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1111+// General Public License for more details.
1212+//
1313+// You should have received a copy of the GNU General Public License
1414+// along with this program. If not, see <http://www.gnu.org/licenses/>.
1515+//
1616+// Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
1717+// SPDX-License-Identifier: GPL-3.0-only
1818+1919+//! `cargo run --example stateful_module`
2020+2121+use windmark::{context::HookContext, Router};
2222+2323+#[derive(Default)]
2424+struct Clicker {
2525+ clicks: usize,
2626+}
2727+2828+impl windmark::Module for Clicker {
2929+ fn on_attach(&mut self, _router: &mut Router) {
3030+ println!("module 'clicker' has been attached!");
3131+ }
3232+3333+ fn on_pre_route(&mut self, context: HookContext) {
3434+ self.clicks += 1;
3535+3636+ println!(
3737+ "module 'clicker' has been called before the route '{}' with {} clicks!",
3838+ context.url.path(),
3939+ self.clicks,
4040+ );
4141+ }
4242+4343+ fn on_post_route(&mut self, context: HookContext) {
4444+ println!(
4545+ "module 'clicker' clicker has been called after the route '{}' with {} \
4646+ clicks!",
4747+ context.url.path(),
4848+ self.clicks,
4949+ );
5050+ }
5151+}
5252+5353+#[windmark::main]
5454+async fn main() -> Result<(), Box<dyn std::error::Error>> {
5555+ let mut router = Router::new();
5656+5757+ router.set_private_key_file("windmark_private.pem");
5858+ router.set_certificate_file("windmark_public.pem");
5959+ #[cfg(feature = "logger")]
6060+ {
6161+ router.enable_default_logger(true);
6262+ }
6363+ router.attach(Clicker::default());
6464+ router.mount("/", windmark::success!("Hello!"));
6565+6666+ router.run().await
6767+}