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
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:
21
src/server/config.rs
Normal file
21
src/server/config.rs
Normal 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()
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod config;
|
||||
pub mod main;
|
||||
|
||||
pub use main::main;
|
||||
|
||||
Reference in New Issue
Block a user