odyssey-server/src/config.rs

27 lines
604 B
Rust

use config::{Config, ConfigError, Environment, File};
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct Settings {
pub bind: String,
}
impl Settings {
pub fn new() -> Result<Self, ConfigError> {
let mut s = Config::new();
// Set defaults
s.set_default("bind", "0.0.0.0")?;
s.set_default("port", 8080)?;
// Try loading from file (config.json/toml/etc)
s.merge(File::with_name("config").required(false))?;
// Add in settings from the environment (with a prefix of SOOS)
s.merge(Environment::with_prefix("soos"))?;
// Deserialize and freeze conf
s.try_into()
}
}