A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: ae43b5b25e9e1daa801956946ac694138440fbd5 (1203 bytes)[doc][blame][raw]
1
use serde::Deserialize;2
use std::fmt;3
use std::fs;5
#[derive(Debug, Clone, Deserialize)]6
pub struct Server {7
pub hostname: String,8
pub port: i32,9
pub options: Options,10
}12
impl fmt::Display for Server {13
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {14
write!(f, "{}:{}", self.hostname, self.port,)15
}16
}18
#[derive(Debug, Clone, Deserialize)]19
pub struct Options {20
pub origin: String,21
}23
#[derive(Debug, Clone, Deserialize)]24
pub struct Database {25
pub hostname: String,26
pub port: i32,27
pub username: String,28
pub password: String,29
pub database: String,30
}32
impl fmt::Display for Database {33
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {34
write!(35
f,36
"postgres://{}:{}@{}:{}/{}?sslmode=disable",37
self.username, self.password, self.hostname, self.port, self.database,38
)39
}40
}42
#[derive(Debug, Clone, Deserialize)]43
pub struct Config {44
pub server: Server,45
pub database: Database,46
}48
impl Config {49
pub fn from_file(path: &str) -> Result<Self, toml::de::Error> {50
let raw = fs::read_to_string(path).expect("Unable to locate config file!");51
toml::from_str(&raw)52
}53
}