From eb40fae2e289ad8ca8bfaac0e193c8b89d96e559 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Wed, 20 Apr 2022 00:30:51 -0700 Subject: feat(modules): random route --- src/modules/random.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/modules/random.rs (limited to 'src/modules/random.rs') diff --git a/src/modules/random.rs b/src/modules/random.rs new file mode 100644 index 0000000..8604d64 --- /dev/null +++ b/src/modules/random.rs @@ -0,0 +1,38 @@ +// This file is part of Locus . +// Copyright (C) 2022-2022 Fuwn +// +// 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 . +// +// Copyright (C) 2022-2022 Fuwn +// SPDX-License-Identifier: GPL-3.0-only + +use rand::seq::SliceRandom; + +pub fn module(router: &mut windmark::Router) { + crate::route::track_mount( + router, + "/random", + "Get redirected to a random route", + Box::new(|_| { + windmark::Response::TemporaryRedirect( + (*crate::ROUTES.lock().unwrap()) + .iter() + .collect::>() + .choose(&mut rand::thread_rng()) + .unwrap() + .0 + .to_string(), + ) + }), + ); +} -- cgit v1.2.3