move config loading to config module

This separates concerns a bit more. We will probably want to extend the
logic for config loading in the future, and that stuff should all live
in the relevant place. This change points us in the right direction.
This commit is contained in:
Charles Hall 2024-06-06 22:44:30 -07:00
parent 2b0bc140cf
commit 6b819d6f2d
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
3 changed files with 40 additions and 13 deletions

View file

@ -1,8 +1,13 @@
use std::net::{IpAddr, Ipv4Addr};
use std::{
net::{IpAddr, Ipv4Addr},
path::Path,
};
use ruma::{OwnedServerName, RoomVersionId};
use serde::Deserialize;
use crate::error;
mod proxy;
use proxy::ProxyConfig;
@ -153,3 +158,20 @@ fn default_turn_ttl() -> u64 {
pub(crate) fn default_default_room_version() -> RoomVersionId {
RoomVersionId::V10
}
/// Load the configuration from the given path
pub(crate) async fn load<P>(path: P) -> Result<Config, error::Config>
where
P: AsRef<Path>,
{
use error::Config as Error;
let path = path.as_ref();
toml::from_str(
&tokio::fs::read_to_string(path)
.await
.map_err(|e| Error::Read(e, path.to_owned()))?,
)
.map_err(|e| Error::Parse(e, path.to_owned()))
}