diff options
| author | Fuwn <[email protected]> | 2022-04-20 00:30:51 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-04-20 00:30:51 -0700 |
| commit | eb40fae2e289ad8ca8bfaac0e193c8b89d96e559 (patch) | |
| tree | cba1c39d706b41f6fe1393adfc0b501ed535bd3d /src/modules/random.rs | |
| parent | refactor(macros): batch_mount files (diff) | |
| download | locus-eb40fae2e289ad8ca8bfaac0e193c8b89d96e559.tar.xz locus-eb40fae2e289ad8ca8bfaac0e193c8b89d96e559.zip | |
feat(modules): random route
Diffstat (limited to 'src/modules/random.rs')
| -rw-r--r-- | src/modules/random.rs | 38 |
1 files changed, 38 insertions, 0 deletions
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 <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 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::<Vec<_>>() + .choose(&mut rand::thread_rng()) + .unwrap() + .0 + .to_string(), + ) + }), + ); +} |