hoc/src/config.rs
Valentin Brandl 84f4aa9be3
All checks were successful
continuous-integration/drone/push Build is passing
Migrate to config v0.12.0
2022-02-26 16:22:36 +01:00

34 lines
955 B
Rust

use config::{Config, ConfigError, Environment, File};
use std::path::PathBuf;
#[derive(Debug, Deserialize)]
pub struct Settings {
/// Path to store cloned repositories
pub repodir: PathBuf,
/// Path to store cache
pub cachedir: PathBuf,
/// Port to listen on
pub port: u16,
/// Interface to listen on
pub host: String,
/// Base URL
pub base_url: String,
/// Number of worker threads
pub workers: usize,
}
impl Settings {
pub fn load() -> Result<Self, ConfigError> {
Config::builder()
.add_source(File::with_name("hoc.toml").required(false))
.add_source(Environment::with_prefix("hoc"))
.set_default("repodir", "./repos")?
.set_default("cachedir", "./cache")?
.set_default("workers", 4)?
.set_default("port", 8080)?
.set_default("host", "0.0.0.0")?
.build()?
.try_deserialize()
}
}