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