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 | |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 3 | use crate::game::oracle::OracleTemplate; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | use crate::secret::Secret; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | pub struct Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | pub addr: String, |
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, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 11 | pub(crate) oracle: OracleTemplate, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | impl Default for Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | fn default() -> Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | addr: "127.0.0.1:6969".into(), |
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), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 21 | oracle: OracleTemplate::Rng, |
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 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | impl Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | pub fn from_env() -> Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 28 | let var = |name| std::env::var(name).ok(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | let defaults = Self::default(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | addr: var("JELQD_ADDR").unwrap_or(defaults.addr), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 32 | secret: var("JELQD_SECRET").map_or(defaults.secret, |s| Secret::new(s.into_bytes())), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 33 | oracle: match var("JELQD_ORACLE").as_deref() { |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 34 | Some("clm") => OracleTemplate::Clm { |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 35 | url: var("JELQD_CLM_URL") |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 36 | .unwrap_or_else(|| "http://127.0.0.1:8700/v1/systemone".into()), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 37 | }, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 38 | _ => defaults.oracle, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 39 | }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | ..defaults |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | } |