A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 3115f29770d6a18974adec45c97c21e3e7dd0962 (1520 bytes)[doc][blame][raw]
1
use serde::Deserialize;2
use std::fmt;3
use std::fs;5
use crate::error::Error;6
use crate::Result;7
use crate::APP_NAME;9
#[derive(Debug, Clone, Deserialize)]10
pub struct Server {11
pub hostname: String,12
pub port: i32,13
pub options: Options,14
}16
impl fmt::Display for Server {17
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {18
write!(f, "{}:{}", self.hostname, self.port,)19
}20
}22
#[derive(Debug, Clone, Deserialize)]23
pub struct Options {24
pub origin: String,25
}27
#[derive(Debug, Clone, Deserialize)]28
pub struct Database {29
pub hostname: String,30
pub port: i32,31
pub username: String,32
pub password: String,33
pub database: String,34
}36
impl fmt::Display for Database {37
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {38
write!(39
f,40
"postgres://{}:{}@{}:{}/{}?sslmode=disable",41
self.username, self.password, self.hostname, self.port, self.database,42
)43
}44
}46
#[derive(Debug, Clone, Deserialize)]47
pub struct Config {48
pub server: Server,49
pub database: Database,50
}52
impl Config {53
pub fn acquire() -> Result<Self> {54
let mut config_path = match dirs::config_dir() {55
Some(config_path) => config_path,56
None => return Err(Error::new("unable to determine config path!")),57
};58
config_path.push(APP_NAME);59
config_path.push("config.toml");60
let raw = fs::read_to_string(&config_path)?;61
let config: Self = toml::from_str(&raw)?;62
Ok(config)63
}64
}