From 1d3eb86024e24e1188734483f415f8c0a32060cf Mon Sep 17 00:00:00 2001 From: Zynh Ludwig Date: Thu, 16 Jan 2025 22:48:57 -0800 Subject: [PATCH] config: add config struct --- src/config.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + 2 files changed, 59 insertions(+) create mode 100644 src/config.rs diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..1c842fb --- /dev/null +++ b/src/config.rs @@ -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, +} diff --git a/src/lib.rs b/src/lib.rs index b9af0bb..3d55b90 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +pub mod config; pub mod db; pub mod router; pub mod state;