atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
9683736a2c5e4af0c861af0df5b33ec31e26cefa
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/config.rsRust38 lines1.0 KB
1
use std::time::Duration;
2
3
use crate::secret::Secret;
4
5
pub struct Config {
6
    pub addr: String,
7
    pub refractory: Duration,
8
    pub secret: Secret,
9
    pub max_runs: usize,
10
    pub idle_ttl: Duration,
11
}
12
13
impl Default for Config {
14
    fn default() -> Self {
15
        Self {
16
            addr: "127.0.0.1:6969".into(),
17
            refractory: Duration::from_secs(30),
18
            secret: Secret::random(),
19
            max_runs: 10_000,
20
            idle_ttl: Duration::from_secs(6 * 60 * 60),
21
        }
22
    }
23
}
24
25
impl Config {
26
    pub fn from_env() -> Self {
27
        let var = |name| std::env::var(name).ok();
28
        let defaults = Self::default();
29
        Self {
30
            addr: var("JELQD_ADDR").unwrap_or(defaults.addr),
31
            refractory: var("JELQD_REFRACTORY_SECS")
32
                .and_then(|s| s.parse().ok())
33
                .map_or(defaults.refractory, Duration::from_secs),
34
            secret: var("JELQD_SECRET").map_or(defaults.secret, |s| Secret::new(s.into_bytes())),
35
            ..defaults
36
        }
37
    }
38
}