use ilo_config::Config;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Default)]
struct QuickstartConfig {
url: Option<String>,
comment: Option<String>,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut config: Config<QuickstartConfig> = Config::load("example-config")?;
let data = config.data_mut();
if data.comment.is_none() {
data.comment = Some(String::from(
"Created by the ilo-config package's quickstart example.",
));
}
let url: &str = data
.url
.get_or_insert_with(|| String::from("https://httpbin.org/get"));
let response = reqwest::blocking::get(url)?;
let text = response.text()?;
println!("Response from configured URL: {text}");
config.save().map_err(|e| e.into())
}