Starting the config service

This commit is contained in:
Z. Charles Dziura 2025-07-25 06:24:01 -04:00
parent fb36716665
commit 26be51ae68
6 changed files with 54 additions and 5 deletions

View file

@ -12,7 +12,7 @@ axum = { version = "0.8", features = [
] }
base64 = "0.22"
blake3 = { version = "1.5", features = ["serde"] }
deadpool-redis = { version = "0.21", features = ["serde"] }
deadpool-redis = { version = "0.22", features = ["serde"] }
futures = "0.3"
http = "1.0"
humantime = "2.1"
@ -32,6 +32,7 @@ rust_decimal = "1.36"
serde = { version = "1.0", features = ["derive", "rc", "std"] }
serde_json = "1.0"
serde_with = "3.9"
snafu = { version = "0.8.6", features = ["futures"] }
sqlx = { version = "0.8", features = [
"default",
"time",
@ -42,7 +43,7 @@ sqlx = { version = "0.8", features = [
] }
time = { version = "0.3", features = ["formatting", "macros"] }
tokio = { version = "1.35", features = ["full"] }
toml = "0.8"
toml = "0.9"
tower = "0.5"
tower-http = { version = "0.6", features = ["full"] }
tracing = "0.1.40"

View file

@ -1,3 +1,3 @@
fn main() {
println!("Hello, world!");
}
mod services;
fn main() {}

View file

@ -0,0 +1,13 @@
use std::io::Error as IoError;
use snafu::Snafu;
use toml::de::Error as TomlDeserializationError;
#[derive(Debug, Snafu)]
pub enum ConfigError {
#[snafu(display("Could not open config file"), visibility(pub(in super)))]
OpenConfig { source: IoError },
#[snafu(display("Invalid config file"), visibility(pub(in super)))]
Format { source: TomlDeserializationError },
}

View file

@ -0,0 +1,5 @@
mod error;
mod service;
pub use error::*;
pub use service::*;

View file

@ -0,0 +1,29 @@
use std::{fs, path::Path};
use serde::Deserialize;
use snafu::ResultExt;
use crate::services::config::{ConfigError, FormatSnafu, error::OpenConfigSnafu};
#[derive(Clone, Debug, Default, Deserialize)]
pub struct Config {
hostname: String,
port: String,
}
impl Config {
pub fn _app_connection_uri(&self) -> String {
format!("{}:{}", self.hostname.as_str(), self.port.as_str())
}
}
impl TryFrom<&Path> for Config {
type Error = ConfigError;
fn try_from(path: &Path) -> Result<Self, Self::Error> {
let buffer = fs::read_to_string(path).context(OpenConfigSnafu)?;
toml::from_str(buffer.as_str()).context(FormatSnafu)
}
}
pub fn read_config() -> Result<Config, ConfigError> {}

1
api/src/services/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod config;