atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
d46f9d0b953a8d854b9d7f39453d483164282ea4
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git

Blame: src/config.rs

782069860236atagen2026-10-10 12:44 UTC1
use std::time::Duration;
782069860236atagen2026-10-10 12:44 UTC2
782069860236atagen2026-10-10 12:44 UTC3
use crate::secret::Secret;
782069860236atagen2026-10-10 12:44 UTC4
782069860236atagen2026-10-10 12:44 UTC5
pub struct Config {
782069860236atagen2026-10-10 12:44 UTC6
    pub addr: String,
782069860236atagen2026-10-10 12:44 UTC7
    pub refractory: Duration,
782069860236atagen2026-10-10 12:44 UTC8
    pub secret: Secret,
782069860236atagen2026-10-10 12:44 UTC9
    pub max_runs: usize,
782069860236atagen2026-10-10 12:44 UTC10
    pub idle_ttl: Duration,
782069860236atagen2026-10-10 12:44 UTC11
}
782069860236atagen2026-10-10 12:44 UTC12
782069860236atagen2026-10-10 12:44 UTC13
impl Default for Config {
782069860236atagen2026-10-10 12:44 UTC14
    fn default() -> Self {
782069860236atagen2026-10-10 12:44 UTC15
        Self {
782069860236atagen2026-10-10 12:44 UTC16
            addr: "127.0.0.1:6969".into(),
782069860236atagen2026-10-10 12:44 UTC17
            refractory: Duration::from_secs(30),
782069860236atagen2026-10-10 12:44 UTC18
            secret: Secret::random(),
782069860236atagen2026-10-10 12:44 UTC19
            max_runs: 10_000,
782069860236atagen2026-10-10 12:44 UTC20
            idle_ttl: Duration::from_secs(6 * 60 * 60),
782069860236atagen2026-10-10 12:44 UTC21
        }
782069860236atagen2026-10-10 12:44 UTC22
    }
782069860236atagen2026-10-10 12:44 UTC23
}
782069860236atagen2026-10-10 12:44 UTC24
782069860236atagen2026-10-10 12:44 UTC25
impl Config {
782069860236atagen2026-10-10 12:44 UTC26
    pub fn from_env() -> Self {
782069860236atagen2026-10-10 12:44 UTC27
        let var = |name| std::env::var(name).ok();
782069860236atagen2026-10-10 12:44 UTC28
        let defaults = Self::default();
782069860236atagen2026-10-10 12:44 UTC29
        Self {
782069860236atagen2026-10-10 12:44 UTC30
            addr: var("JELQD_ADDR").unwrap_or(defaults.addr),
782069860236atagen2026-10-10 12:44 UTC31
            refractory: var("JELQD_REFRACTORY_SECS")
782069860236atagen2026-10-10 12:44 UTC32
                .and_then(|s| s.parse().ok())
782069860236atagen2026-10-10 12:44 UTC33
                .map_or(defaults.refractory, Duration::from_secs),
782069860236atagen2026-10-10 12:44 UTC34
            secret: var("JELQD_SECRET").map_or(defaults.secret, |s| Secret::new(s.into_bytes())),
782069860236atagen2026-10-10 12:44 UTC35
            ..defaults
782069860236atagen2026-10-10 12:44 UTC36
        }
782069860236atagen2026-10-10 12:44 UTC37
    }
782069860236atagen2026-10-10 12:44 UTC38
}