First commit: check status without sending email
[stakingWatchdog.git] / src / config.rs
1 use std::{fs::File, time};
2
3 use anyhow::Result;
4 use ron::{
5 de::from_reader,
6 ser::{to_writer_pretty, PrettyConfig},
7 };
8 use serde::{Deserialize, Serialize};
9
10 #[derive(Debug, Clone, Deserialize, Serialize)]
11 pub struct Config {
12 pub pub_keys: Vec<String>,
13 }
14
15 impl Config {
16 pub fn default() -> Self {
17 Config { pub_keys: vec![] }
18 }
19
20 pub fn read(file_path: &str) -> Result<Config> {
21 match File::open(file_path) {
22 Ok(file) => from_reader(file).map_err(|e| e.into()),
23 // The file doesn't exit -> create it with default values.
24 Err(_) => {
25 let file = File::create(file_path)?;
26 let default_config = Config::default();
27 to_writer_pretty(file, &default_config, PrettyConfig::new())?;
28 Ok(default_config)
29 }
30 }
31 }
32 }