config: add config struct

This commit is contained in:
Zynh Ludwig 2025-01-16 22:48:57 -08:00
parent 65ef7b1dfb
commit 1d3eb86024
2 changed files with 59 additions and 0 deletions

58
src/config.rs Normal file
View file

@ -0,0 +1,58 @@
//! Runtime configuration construction
//!
//! This module handles fetching setting from user with environment
//! variables, as well as providing a default configuration set
//!
//! The structure of [Settings] is a bit weird because of one of the ways
//! that [config] seperators work by default. See [Environment](config::Environment).
//! Realistically we could also just use field names like `cache_dir` and it should have
//! the same effect if at some point having the substructs defined like this is annoying.
use std::path::PathBuf;
/// primary settings container
#[derive(Debug)]
pub struct Settings {
/// main upload cache setings
pub cache: Cache,
/// static serve settings
pub dist: Dist,
/// database settings
pub database: Database,
}
/// main upload cache setings
#[derive(Debug)]
pub struct Cache {
/// directory that the cached uploads are stored
///
/// set with `NZ_CACHE_DIR`
///
/// See:
/// - [crate::router::download]
/// - [crate::router::upload]
pub dir: PathBuf,
}
/// static serve settings
#[derive(Debug)]
pub struct Dist {
/// directory that nyazoom serves statically.
///
/// set with `NZ_DIST_URL`
pub dir: PathBuf,
}
/// database settings
#[derive(Debug)]
pub struct Database {
/// database url used by [sqlx] to connect to the database
///
/// currently nyazoom only supports sqlite databases
///
/// set with `NZ_DATABASE_URL` env variable
///
/// See:
/// - [crate::db]
pub url: String,
}

View file

@ -1,3 +1,4 @@
pub mod config;
pub mod db;
pub mod router;
pub mod state;