This commit is contained in:
Peter Schiwy
2024-06-20 14:50:36 +02:00
parent 1d60fc5a3f
commit 44931afbe7
23 changed files with 431 additions and 25 deletions

53
src/config.rs Normal file
View File

@@ -0,0 +1,53 @@
use anyhow::Error;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub http: Http,
pub database: Database,
pub graphql: Grapthql,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Http {
pub host: String,
pub port: u16,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Database {
pub url: String,
pub pool_size: u32,
pub max_lifetime: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Grapthql {
pub schema_location: String,
}
impl Config {
pub fn load() -> Result<Self, Error> {
dotenv::dotenv().ok();
let http = envy::prefixed("HTTP_")
.from_env::<Http>()
.expect("Failed to load http config");
let database = envy::prefixed("DATABASE_")
.from_env::<Database>()
.expect("Failed to load database config");
let graphql = envy::prefixed("GRAPHQL_")
.from_env::<Grapthql>()
.expect("Failed to load graphql config");
let config = Self {
http,
database,
graphql,
};
Ok(config)
}
}