mirror of
https://codeberg.org/demostf/frontend.git
synced 2026-08-02 12:24:52 +02:00
demo list and page
This commit is contained in:
parent
23d9d55984
commit
667f5eae04
32 changed files with 4784 additions and 5 deletions
48
src/config.rs
Normal file
48
src/config.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
use crate::Result;
|
||||
use config::{Environment, File};
|
||||
use serde::Deserialize;
|
||||
use sqlx::postgres::PgConnectOptions;
|
||||
use sqlx::PgPool;
|
||||
use std::net::IpAddr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
pub listen: Listen,
|
||||
pub database: DbConfig,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load(path: &str) -> Result<Self> {
|
||||
let s = config::Config::builder()
|
||||
.add_source(File::with_name(path))
|
||||
.add_source(Environment::default().separator("_"))
|
||||
.build()?;
|
||||
|
||||
Ok(s.try_deserialize()?)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct DbConfig {
|
||||
hostname: String,
|
||||
username: String,
|
||||
password: String,
|
||||
}
|
||||
|
||||
impl DbConfig {
|
||||
pub async fn connect(&self) -> Result<PgPool> {
|
||||
let opt = PgConnectOptions::new()
|
||||
.host(&self.hostname)
|
||||
.username(&self.username)
|
||||
.password(&self.password);
|
||||
Ok(PgPool::connect_with(opt).await?)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Listen {
|
||||
Socket { path: PathBuf },
|
||||
Tcp { address: IpAddr, port: u16 },
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue