Create Config and config_load
All checks were successful
Push Workflows / rustfmt (push) Successful in 6s
Push Workflows / tailwind-build (push) Successful in 6s
Push Workflows / test (push) Successful in 20s
Push Workflows / clippy (push) Successful in 15s
Push Workflows / docs (push) Successful in 21s
Push Workflows / build (push) Successful in 43s
Push Workflows / nix-build (push) Successful in 4m56s

This commit is contained in:
2026-06-23 21:16:32 -04:00
parent 5f910d77ca
commit e38fa9ac0e
2 changed files with 22 additions and 0 deletions

21
src/server/config.rs Normal file
View File

@@ -0,0 +1,21 @@
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
/// Top-level application configuration
pub struct Config {}
/// Parse configuration from the expected files and environment variables
pub fn load_config() -> Result<Config, config::ConfigError> {
use config::{Environment, File};
let pkg_name = env!("CARGO_PKG_NAME");
config::Config::builder()
.set_default("server.port", 8080)?
.add_source(File::with_name(&format!("/etc/{pkg_name}/config")).required(false))
.add_source(File::with_name(&format!("/etc/{pkg_name}")).required(false))
.add_source(File::with_name("config").required(false))
.add_source(Environment::with_prefix(pkg_name).separator("_"))
.build()?
.try_deserialize()
}

View File

@@ -1,3 +1,4 @@
pub mod config;
pub mod main; pub mod main;
pub use main::main; pub use main::main;