posemesh_domain_http/
config.rs

1use serde::Deserialize;
2#[cfg(target_family = "wasm")]
3use wasm_bindgen::prelude::*;
4
5#[cfg_attr(target_family = "wasm", wasm_bindgen(getter_with_clone))]
6#[derive(Debug, Clone, Deserialize)]
7pub struct Config {
8    pub api_url: String,
9    pub dds_url: String,
10    pub client_id: String,
11    pub app_key: Option<String>,
12    pub app_secret: Option<String>,
13    pub email: Option<String>,
14    pub password: Option<String>,
15}
16
17impl Config {
18    pub fn from_env() -> Result<Self, std::env::VarError> {
19        Ok(Config {
20            api_url: std::env::var("API_URL")?,
21            dds_url: std::env::var("DDS_URL")?,
22            client_id: std::env::var("CLIENT_ID")?,
23            app_key: std::env::var("APP_KEY").map_or(None, |v| Some(v)),
24            app_secret: std::env::var("APP_SECRET").map_or(None, |v| Some(v)),
25            email: std::env::var("POSEMESH_EMAIL").map_or(None, |v| Some(v)),
26            password: std::env::var("POSEMESH_PASSWORD").map_or(None, |v| Some(v)),
27        })
28    }
29}