Create Config and config_load
Some checks failed
Push Workflows / rustfmt (push) Failing after 5s
Push Workflows / tailwind-build (push) Successful in 5s
Push Workflows / docs (push) Successful in 26s
Push Workflows / test (push) Failing after 35s
Push Workflows / clippy (push) Failing after 30s
Push Workflows / build (push) Failing after 57s
Push Workflows / nix-build (push) Has been cancelled

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

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

@@ -0,0 +1,22 @@
use serde::Deserialize;
#[derive(Debug, Clone, 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 main;
pub mod config;
pub use main::main;