41 lines
897 B
Rust
41 lines
897 B
Rust
use serde::Deserialize;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct Config {
|
|
pub database: DatabaseConfig,
|
|
pub server: ServerConfig,
|
|
pub storage: StorageConfig,
|
|
}
|
|
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct DatabaseConfig {
|
|
pub url: String,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct ServerConfig {
|
|
pub host: String,
|
|
pub port: u16,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct StorageConfig {
|
|
pub images_dir: PathBuf,
|
|
pub thumbnails_dir: PathBuf,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn load() -> Result<Self, config::ConfigError> {
|
|
let config = config::Config::builder()
|
|
.add_source(config::File::with_name("config"))
|
|
.build()?;
|
|
|
|
config.try_deserialize()
|
|
}
|
|
|
|
pub fn server_address(&self) -> String {
|
|
format!("{}:{}", self.server.host, self.server.port)
|
|
}
|
|
} |