an http based roguelike rpg about jelqing
Blame: src/config.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | use std::time::Duration; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | use crate::secret::Secret; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | pub struct Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | pub addr: String, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | pub refractory: Duration, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | pub secret: Secret, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | pub max_runs: usize, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | pub idle_ttl: Duration, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | impl Default for Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | fn default() -> Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | addr: "127.0.0.1:6969".into(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | refractory: Duration::from_secs(30), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | secret: Secret::random(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | max_runs: 10_000, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | idle_ttl: Duration::from_secs(6 * 60 * 60), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 21 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 22 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 24 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 25 | impl Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | pub fn from_env() -> Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | let var = |name| std::env::var(name).ok(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 28 | let defaults = Self::default(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | addr: var("JELQD_ADDR").unwrap_or(defaults.addr), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | refractory: var("JELQD_REFRACTORY_SECS") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 32 | .and_then(|s| s.parse().ok()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | .map_or(defaults.refractory, Duration::from_secs), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 34 | secret: var("JELQD_SECRET").map_or(defaults.secret, |s| Secret::new(s.into_bytes())), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 35 | ..defaults |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 38 | } |