Files
lighthouse/watch/src/config.rs
Mac L 8630ddfec4 Add beacon.watch (#3362)
> This is currently a WIP and all features are subject to alteration or removal at any time.

## Overview

The successor to #2873.

Contains the backbone of `beacon.watch` including syncing code, the initial API, and several core database tables.

See `watch/README.md` for more information, requirements and usage.
2023-04-03 05:35:11 +00:00

51 lines
1.4 KiB
Rust

use crate::blockprint::Config as BlockprintConfig;
use crate::database::Config as DatabaseConfig;
use crate::server::Config as ServerConfig;
use crate::updater::Config as UpdaterConfig;
use serde::{Deserialize, Serialize};
use std::fs::File;
pub const LOG_LEVEL: &str = "debug";
fn log_level() -> String {
LOG_LEVEL.to_string()
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
#[serde(default)]
pub blockprint: BlockprintConfig,
#[serde(default)]
pub database: DatabaseConfig,
#[serde(default)]
pub server: ServerConfig,
#[serde(default)]
pub updater: UpdaterConfig,
/// The minimum severity for log messages.
#[serde(default = "log_level")]
pub log_level: String,
}
impl Default for Config {
fn default() -> Self {
Self {
blockprint: BlockprintConfig::default(),
database: DatabaseConfig::default(),
server: ServerConfig::default(),
updater: UpdaterConfig::default(),
log_level: log_level(),
}
}
}
impl Config {
pub fn load_from_file(path_to_file: String) -> Result<Config, String> {
let file =
File::open(path_to_file).map_err(|e| format!("Error reading config file: {:?}", e))?;
let config: Config = serde_yaml::from_reader(file)
.map_err(|e| format!("Error parsing config file: {:?}", e))?;
Ok(config)
}
}