display client info and unlock errors to user

This commit is contained in:
Joseph Montanaro committed 2022-12-21 13:43:37 -08:00
1 parent 69475604c0
commit 50f0985f4f
8 files changed
+95 -27

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
use std::net::Ipv4Addr;
use std::path::PathBuf;
pub struct AppConfig {
pub db_path: PathBuf,
pub listen_addr: Ipv4Addr,
pub listen_port: u16,
}
impl Default for AppConfig {
fn default() -> Self {
AppConfig {
db_path: get_or_create_db_path(),
listen_addr: Ipv4Addr::LOCALHOST,
listen_port: 19_923
}
}
}
fn get_or_create_db_path() -> PathBuf {
if cfg!(debug_assertions) {
return PathBuf::from("./creddy.db");
}
let mut parent = std::env::var("HOME")
.map(|h| {
let mut p = PathBuf::from(h);
p.push(".config");
p
})
.unwrap_or(PathBuf::from("."));
parent.push("creddy.db");
parent
}