Some checks failed
Push Workflows / rustfmt (push) Failing after 6s
Push Workflows / tailwind-build (push) Successful in 5s
Push Workflows / docs (push) Successful in 23s
Push Workflows / clippy (push) Successful in 42s
Push Workflows / test (push) Successful in 51s
Push Workflows / build (push) Successful in 1m15s
Push Workflows / nix-build (push) Has been cancelled
22 lines
767 B
Rust
22 lines
767 B
Rust
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()
|
|
}
|