blob: 11742d9c24cfc36013fb208b46c4abb0736b49b0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
use crate::{commands::CommandsConfig, handlers::X500MapperConfig};
use anyhow::{Context, Result};
use serde::Deserialize;
use std::{fs, path::Path};
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
pub database_url: String,
pub discord_token: String,
pub commands: CommandsConfig,
pub x500_mapper: X500MapperConfig,
}
impl Config {
pub fn read_from_file(path: &Path) -> Result<Config> {
let config_str = fs::read_to_string(path)
.with_context(|| format!("failed to read {}", path.display()))?;
toml::from_str(&config_str).with_context(|| format!("failed to parse {}", path.display()))
}
}
|