aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-04-19 23:53:54 -0700
committerFuwn <[email protected]>2022-04-19 23:53:54 -0700
commit70a0c63a039b833f376d269f4a9ff87d1d31d5d9 (patch)
treea65d92cf2a35ef2589d7a2041a0d50419450edd8 /src
parentfeat(search): log when spawning indexer (diff)
downloadlocus-70a0c63a039b833f376d269f4a9ff87d1d31d5d9.tar.xz
locus-70a0c63a039b833f376d269f4a9ff87d1d31d5d9.zip
refactor(main): create flexible rount mount timer
Diffstat (limited to 'src')
-rw-r--r--src/main.rs110
1 files changed, 58 insertions, 52 deletions
diff --git a/src/main.rs b/src/main.rs
index a0c3f3c..9abb28c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -76,6 +76,19 @@ struct Main<'a> {
mini_commit: &'a str,
}
+fn time_mounts<T>(context: &str, timer: &mut Instant, mut mounter: T)
+where T: FnMut() {
+ mounter();
+
+ info!(
+ "{} mounts took {}ms",
+ context,
+ timer.elapsed().as_nanos() as f64 / 1_000_000.0
+ );
+
+ *timer = Instant::now();
+}
+
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
std::env::set_var("RUST_LOG", "windmark,locus=trace");
@@ -132,58 +145,51 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
);
time_mount = Instant::now();
- router.attach_stateless(modules::uptime::module);
- router.attach_stateless(modules::sitemap::module);
- router.attach_stateless(modules::search::module);
- router.attach_stateless(modules::remarks::module);
- router.attach_stateless(modules::multi_blog::module);
-
- info!(
- "module mounts took {}ms",
- time_mount.elapsed().as_nanos() as f64 / 1_000_000.0
- );
- time_mount = Instant::now();
-
- mount_file!(
- router,
- "/robots.txt",
- "Crawler traffic manager, for robots, not humans",
- "robots.txt"
- );
- mount_file!(
- router,
- "/favicon.txt",
- "This Gemini capsule's icon",
- "favicon.txt"
- );
- mount_page!(router, "/", "This Gemini capsule's homepage", "index");
- mount_page!(router, "/contact", "Many ways to contact Fuwn", "contact");
- mount_page!(router, "/donate", "Many ways to donate to Fuwn", "donate");
- mount_page!(
- router,
- "/gemini",
- "Information and resources for the Gemini protocol",
- "gemini"
- );
- mount_page!(
- router,
- "/gopher",
- "Information and resources for the Gopher protocol",
- "gopher"
- );
- mount_page!(router, "/interests", "A few interests of Fuwn", "interests");
- mount_page!(router, "/skills", "A few skills of Fuwn", "skills");
- mount_page!(
- router,
- "/licensing",
- "The licensing terms of this Gemini capsule",
- "licensing"
- );
-
- info!(
- "static mounts took {}ms",
- time_mount.elapsed().as_nanos() as f64 / 1_000_000.0
- );
+ time_mounts("module", &mut time_mount, || {
+ router.attach_stateless(modules::uptime::module);
+ router.attach_stateless(modules::sitemap::module);
+ router.attach_stateless(modules::search::module);
+ router.attach_stateless(modules::remarks::module);
+ router.attach_stateless(modules::multi_blog::module);
+ });
+
+ time_mounts("static", &mut time_mount, || {
+ mount_file!(
+ router,
+ "/robots.txt",
+ "Crawler traffic manager, for robots, not humans",
+ "robots.txt"
+ );
+ mount_file!(
+ router,
+ "/favicon.txt",
+ "This Gemini capsule's icon",
+ "favicon.txt"
+ );
+ mount_page!(router, "/", "This Gemini capsule's homepage", "index");
+ mount_page!(router, "/contact", "Many ways to contact Fuwn", "contact");
+ mount_page!(router, "/donate", "Many ways to donate to Fuwn", "donate");
+ mount_page!(
+ router,
+ "/gemini",
+ "Information and resources for the Gemini protocol",
+ "gemini"
+ );
+ mount_page!(
+ router,
+ "/gopher",
+ "Information and resources for the Gopher protocol",
+ "gopher"
+ );
+ mount_page!(router, "/interests", "A few interests of Fuwn", "interests");
+ mount_page!(router, "/skills", "A few skills of Fuwn", "skills");
+ mount_page!(
+ router,
+ "/licensing",
+ "The licensing terms of this Gemini capsule",
+ "licensing"
+ );
+ });
std::thread::spawn(search::index);