1 use ron
::{ de
::from_reader
, ser
::to_writer
};
2 use serde
::{ Deserialize
, Serialize
};
3 use std
::{ fs
::File
, time
};
5 use crate::error
::Result
;
7 #[derive(Debug, Clone, Deserialize, Serialize)]
9 pub delay_between_check
: time
::Duration
,
12 pub domains
: Vec
<String
>,
17 pub fn default() -> Self {
18 Config
{ delay_between_check
: time
::Duration
::from_secs(120), api_key
: String
::from(""), fqdn
: String
::from(""), domains
: Vec
::new(), ttl
: 300 }
21 pub fn read(file_path
: &str) -> Result
<Config
> {
22 match File
::open(file_path
) {
23 Ok(file
) => from_reader(file
).map_err(|e
| e
.into()),
24 // The file doesn't exit -> create it with default values.
26 let file
= File
::create(file_path
)?
;
27 let default_config
= Config
::default();
28 to_writer(file
, &default_config
)?
;