diff options
| author | Fuwn <[email protected]> | 2022-04-19 23:41:09 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-04-19 23:41:09 -0700 |
| commit | a7c661cd6142c8bc6f5783948c173ad0514827df (patch) | |
| tree | e217f4f56a5e6e2eb52e8c6c1957f86289a59370 /src/modules | |
| parent | refactor(modules): move remarks to modules module (diff) | |
| download | locus-a7c661cd6142c8bc6f5783948c173ad0514827df.tar.xz locus-a7c661cd6142c8bc6f5783948c173ad0514827df.zip | |
refactor(modules): move uptime to modules module
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/mod.rs | 1 | ||||
| -rw-r--r-- | src/modules/uptime.rs | 46 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/modules/mod.rs b/src/modules/mod.rs index a41bf2b..c5d4aaa 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -20,3 +20,4 @@ pub mod multi_blog; pub mod remarks; pub mod search; pub mod sitemap; +pub mod uptime; diff --git a/src/modules/uptime.rs b/src/modules/uptime.rs new file mode 100644 index 0000000..0725933 --- /dev/null +++ b/src/modules/uptime.rs @@ -0,0 +1,46 @@ +// This file is part of Locus <https://github.com/gemrest/locus>. +// 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 + +use std::lazy::SyncLazy; + +use tokio::time::Instant; + +static UPTIME: SyncLazy<Instant> = SyncLazy::new(Instant::now); + +pub fn module(router: &mut windmark::Router) { + crate::route::track_mount( + router, + "/uptime", + "The uptime of Locus (A.K.A., The Locus Epoch). (\\?[s|ms|mu|ns]?)?", + Box::new(move |context| { + windmark::Response::Success(context.url.query().map_or_else( + || UPTIME.elapsed().as_nanos().to_string(), + |query| { + match query { + "secs" | "seconds" | "s" => UPTIME.elapsed().as_secs().to_string(), + "milli" | "milliseconds" | "ms" => + UPTIME.elapsed().as_millis().to_string(), + "micro" | "microseconds" | "mu" => + UPTIME.elapsed().as_micros().to_string(), + _ => UPTIME.elapsed().as_nanos().to_string(), + } + }, + )) + }), + ); +} |