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