simple-web-app

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

config.rs (599B)


      1 use std::env;
      2 
      3 pub struct Config {
      4     pub db_path: String,
      5     pub debug: bool,
      6     pub addr: String,
      7     pub smtp_addr: String,
      8     pub smtp_from: String,
      9     pub site_url: String,
     10 }
     11 
     12 fn env(name: &str) -> String {
     13     env::var(name).unwrap_or_else(|_| panic!("{name} must be set"))
     14 }
     15 
     16 impl Config {
     17     pub fn from_env() -> Self {
     18         Self {
     19             db_path: env("DB_PATH"),
     20             debug: env("DEBUG") == "true",
     21             addr: env("ADDR"),
     22             smtp_addr: env("SMTP_ADDR"),
     23             smtp_from: env("SMTP_FROM"),
     24             site_url: env("SITE_URL"),
     25         }
     26     }
     27 }