Initial commit
This commit is contained in:
commit
b9ce73b51d
19 files changed
+2112
No files matched your search
@@ -0,0 +1,25 @@
|
||||
use std::env;
|
||||
|
||||
use secrecy::SecretString;
|
||||
use thiserror::Error;
|
||||
|
||||
pub struct Config {
|
||||
pub server_secret: SecretString,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ConfigError {
|
||||
#[error("Missing SERVER_SECRET")]
|
||||
MissingServerSecret,
|
||||
#[error("Unknown error: #{0}")]
|
||||
Unknown(anyhow::Error),
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new() -> Result<Self, ConfigError> {
|
||||
dotenvy::dotenv().map_err(|err| ConfigError::Unknown(err.into()))?;
|
||||
let server_secret = env::var("SERVER_SECRET").map(SecretString::from).map_err(|_| ConfigError::MissingServerSecret)?;
|
||||
Ok(Self{server_secret})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user