Skip to main content

endpoint_validator/parser/
loader.rs

1use crate::parser::{Config, Services};
2use anyhow::{Context, Result};
3use serde_json::from_reader;
4use std::fs::{self, File};
5use std::path::Path;
6
7pub fn load_services<P: AsRef<Path>>(path: P) -> Result<Services> {
8    let file = File::open(&path).context("Failed to open services.json file")?;
9    let services: Services = from_reader(file).context("Failed to parse services.json")?;
10    Ok(services)
11}
12
13pub fn load_config(path: &str) -> Result<Config> {
14    let config_content = fs::read_to_string(path)
15        .with_context(|| format!("Failed to read config file: {}", path))?;
16    let config: Config =
17        toml::from_str(&config_content).with_context(|| "Failed to parse config file")?;
18
19    Ok(config)
20}