diff options
| author | Fuwn <[email protected]> | 2023-03-29 00:12:40 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-03-29 00:12:40 -0700 |
| commit | a08cf3fe2bf05551044951432242d0e15a5a040d (patch) | |
| tree | 1366ea926b516d0a8f3475c671b5fc152d0c8931 /src/modules | |
| parent | deps(vergen): 7.0.0 -> 8.0.0 (diff) | |
| download | locus-a08cf3fe2bf05551044951432242d0e15a5a040d.tar.xz locus-a08cf3fe2bf05551044951432242d0e15a5a040d.zip | |
feat(uptime): query string to query key value pair
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/uptime.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/modules/uptime.rs b/src/modules/uptime.rs index 774fb37..6f33433 100644 --- a/src/modules/uptime.rs +++ b/src/modules/uptime.rs @@ -29,19 +29,22 @@ pub fn module(router: &mut windmark::Router) { "/uptime", "The uptime of Locus (A.K.A., The Locus Epoch). (\\?[s|ms|mu|ns]?)?", Box::new(move |context| { - let response = 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(), - } - }, - ); + let response = windmark::utilities::queries_from_url(context.url) + .get("unit") + .map_or_else( + || UPTIME.elapsed().as_nanos().to_string(), + |query| { + match query.as_str() { + "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(), + } + }, + ); crate::route::cache(&context, &response); |