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
,
11 pub domains
: Vec
<(String
, String
)>, // Hostname, domain.
16 pub fn default() -> Self {
17 Config
{ delay_between_check
: time
::Duration
::from_secs(120), api_key
: String
::from(""), domains
: Vec
::new(), ttl
: 300 }
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.
25 let file
= File
::create(file_path
)?
;
26 let default_config
= Config
::default();
27 to_writer(file
, &default_config
)?
;