This commit is contained in:
lychang
2026-03-20 02:31:07 +08:00
commit 5893cd5e31
19 changed files with 5653 additions and 0 deletions

41
src/config.rs Normal file
View File

@@ -0,0 +1,41 @@
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)
}
}