mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-29 10:54:24 +00:00
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.
This commit is contained in:
50
watch/src/config.rs
Normal file
50
watch/src/config.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user