pgui_api/config.rs
1use std::env;
2
3#[derive(Debug)]
4pub struct Config {
5 pub pg_conn_str: String,
6}
7
8impl Default for Config {
9 fn default() -> Self {
10 Self {
11 pg_conn_str: from_env_default(
12 "POSTGRES_CONNECTION",
13 "postgresql://postgres:postgres@0.0.0.0:5432/postgres",
14 ),
15 }
16 }
17}
18
19/// source a variable from environment - use default if not exists
20fn from_env_default(key: &str, default: &str) -> String {
21 env::var(key).unwrap_or_else(|_| default.to_owned())
22}