wasm_ping/config/
mod.rs
1use std::env;
2
3use anyhow::{Context, Result};
4
5#[derive(Debug, Clone)]
6pub(crate) struct Config {
7 pub(crate) transport: String,
8 pub(crate) sec_protocol: Option<String>,
9 pub(crate) muxer: Option<String>,
10 pub(crate) ip: String,
11 pub(crate) is_dialer: bool,
12 pub(crate) test_timeout: u64,
13 pub(crate) redis_addr: String,
14}
15
16impl Config {
17 pub(crate) fn from_env() -> Result<Self> {
18 let transport =
19 env::var("transport").context("transport environment variable is not set")?;
20 let ip = env::var("ip").context("ip environment variable is not set")?;
21 let is_dialer = env::var("is_dialer")
22 .unwrap_or_else(|_| "true".into())
23 .parse::<bool>()?;
24 let test_timeout = env::var("test_timeout_seconds")
25 .unwrap_or_else(|_| "180".into())
26 .parse::<u64>()?;
27 let redis_addr = env::var("redis_addr")
28 .map(|addr| format!("redis://{addr}"))
29 .unwrap_or_else(|_| "redis://redis:6379".into());
30
31 let sec_protocol = env::var("security").ok();
32 let muxer = env::var("muxer").ok();
33
34 Ok(Self {
35 transport,
36 sec_protocol,
37 muxer,
38 ip,
39 is_dialer,
40 test_timeout,
41 redis_addr,
42 })
43 }
44}