mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-05-25 11:48:06 +00:00
3e553eaf60
* Add chapter 4 code. * Add logger middleware. * Add env_logger. * Instrumented. * Test logs. * Introduce instrument. * Refactor handler. * Use TracingLogger. * Update. * Fix linter error.
39 lines
946 B
Rust
39 lines
946 B
Rust
#[derive(serde::Deserialize)]
|
|
pub struct Settings {
|
|
pub database: DatabaseSettings,
|
|
pub application_port: u16,
|
|
}
|
|
|
|
#[derive(serde::Deserialize)]
|
|
pub struct DatabaseSettings {
|
|
pub username: String,
|
|
pub password: String,
|
|
pub port: u16,
|
|
pub host: String,
|
|
pub database_name: String,
|
|
}
|
|
|
|
impl DatabaseSettings {
|
|
pub fn connection_string(&self) -> String {
|
|
format!(
|
|
"postgres://{}:{}@{}:{}/{}",
|
|
self.username, self.password, self.host, self.port, self.database_name
|
|
)
|
|
}
|
|
|
|
pub fn connection_string_without_db(&self) -> String {
|
|
format!(
|
|
"postgres://{}:{}@{}:{}",
|
|
self.username, self.password, self.host, self.port
|
|
)
|
|
}
|
|
}
|
|
|
|
pub fn get_configuration() -> Result<Settings, config::ConfigError> {
|
|
let mut settings = config::Config::default();
|
|
|
|
settings.merge(config::File::with_name("configuration"))?;
|
|
|
|
settings.try_into()
|
|
}
|