/
mcmare
/
RustAPI
Обзор
Документация
Войти
/
mcmare
/
RustAPI
Код
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
engine/src/config/mod.rs
48 строк
2 KB
mcmare
Wire up server binary, sample config, and README
18 июл 2026, 16:41
18 июл 2026, 16:41
f181395
Код
Авторство
О чём код?
mod auth; mod connections; mod endpoint; mod field_type; pub use auth::load_auth_tokens; pub use connections::{ConnectionDef, DbDriver}; pub use endpoint::{CrudOperation, EndpointDef, EndpointKind, HttpMethod}; pub use field_type::FieldType; use anyhow::{bail, Result}; use std::{collections::HashMap, path::Path}; #[derive(Debug)] pub struct Config { pub connections: HashMap<String, ConnectionDef>, pub endpoints: Vec<EndpointDef>, } /// Loads and validates everything under `config_dir`: /// `connections.yaml` + every `.yaml`/`.yml` file under `endpoints/`. /// Fails fast with a message naming the offending file/field rather than panicking, /// since this config is meant to be hand-edited by non-Rust operators. pub fn load_config(config_dir: &Path) -> Result<Config> { let connections = connections::load_connections(&config_dir.join("connections.yaml"))?; let endpoints = endpoint::load_endpoints(&config_dir.join("endpoints"), config_dir)?; for ep in &endpoints { if let EndpointKind::Crud { connection, .. } = &ep.kind { if !connections.contains_key(connection) { bail!( "{}: references unknown connection '{connection}' (declared connections: {})", ep.source_file.display(), if connections.is_empty() { "<none>".to_string() } else { connections.keys().cloned().collect::<Vec<_>>().join(", ") } ); } } } Ok(Config { connections, endpoints, }) }