()
| 30 | |
| 31 | impl Config { |
| 32 | pub fn new() -> Result<Config, handle_errors::Error> { |
| 33 | dotenvy::dotenv().ok(); |
| 34 | let config = Config::parse(); |
| 35 | |
| 36 | if env::var("BAD_WORDS_API_KEY").is_err() { |
| 37 | panic!("BadWords API key not set"); |
| 38 | } |
| 39 | |
| 40 | if env::var("PASETO_KEY").is_err() { |
| 41 | panic!("PASETO_KEY not set"); |
| 42 | } |
| 43 | |
| 44 | let port = std::env::var("PORT") |
| 45 | .ok() |
| 46 | .map(|val| val.parse::<u16>()) |
| 47 | .unwrap_or(Ok(config.port)) |
| 48 | .map_err(handle_errors::Error::ParseError)?; |
| 49 | |
| 50 | let db_user = |
| 51 | env::var("POSTGRES_USER").unwrap_or(config.db_user.to_owned()); |
| 52 | let db_password = env::var("POSTGRES_PASSWORD").unwrap(); |
| 53 | let db_host = |
| 54 | env::var("POSTGRES_HOST").unwrap_or(config.db_host.to_owned()); |
| 55 | let db_port = env::var("POSTGRES_PORT") |
| 56 | .unwrap_or(config.db_port.to_string()); |
| 57 | let db_name = |
| 58 | env::var("POSTGRES_DB").unwrap_or(config.db_name.to_owned()); |
| 59 | |
| 60 | Ok(Config { |
| 61 | log_level: config.log_level, |
| 62 | port, |
| 63 | db_user, |
| 64 | db_password, |
| 65 | db_host, |
| 66 | db_port: db_port |
| 67 | .parse::<u16>() |
| 68 | .map_err(handle_errors::Error::ParseError)?, |
| 69 | db_name, |
| 70 | }) |
| 71 | } |
| 72 | } |
nothing calls this directly
no outgoing calls
no test coverage detected