main
parent
3a50424a35
commit
26b4c335c6
|
@ -0,0 +1,25 @@
|
|||
use std::{
|
||||
fmt::Debug,
|
||||
fs::File,
|
||||
io::Read,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
pub fn load <
|
||||
T: DeserializeOwned,
|
||||
P: AsRef <Path> + Debug
|
||||
> (
|
||||
config_file_path: P
|
||||
) -> T {
|
||||
let mut f = File::open (&config_file_path).unwrap_or_else (|_| panic! ("Can't open {:?}", config_file_path));
|
||||
let mut buffer = vec! [0u8; 4096];
|
||||
let bytes_read = f.read (&mut buffer).unwrap_or_else (|_| panic! ("Can't read {:?}", config_file_path));
|
||||
buffer.truncate (bytes_read);
|
||||
|
||||
{
|
||||
let config_s = String::from_utf8 (buffer).unwrap_or_else (|_| panic! ("Can't parse {:?} as UTF-8", config_file_path));
|
||||
toml::from_str (&config_s).unwrap_or_else (|_| panic! ("Can't parse {:?} as TOML", config_file_path))
|
||||
}
|
||||
}
|
|
@ -6,24 +6,14 @@ use std::{
|
|||
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
mod load_toml;
|
||||
|
||||
use ptth::relay;
|
||||
use ptth::relay::RelayState;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main () -> Result <(), Box <dyn Error>> {
|
||||
use std::io::Read;
|
||||
|
||||
let config_file = {
|
||||
let config_file_path = "config/ptth_relay.toml";
|
||||
|
||||
let mut f = File::open (config_file_path).unwrap_or_else (|_| panic! ("Can't open {:?}", config_file_path));
|
||||
let mut buffer = vec! [0u8; 4096];
|
||||
let bytes_read = f.read (&mut buffer).unwrap_or_else (|_| panic! ("Can't read {:?}", config_file_path));
|
||||
buffer.truncate (bytes_read);
|
||||
|
||||
let config_s = String::from_utf8 (buffer).unwrap_or_else (|_| panic! ("Can't parse {:?} as UTF-8", config_file_path));
|
||||
toml::from_str (&config_s).unwrap_or_else (|_| panic! ("Can't parse {:?} as TOML", config_file_path))
|
||||
};
|
||||
let config_file = load_toml::load ("config/ptth_relay.toml");
|
||||
|
||||
eprintln! ("ptth_relay Git version: {:?}", ptth::git_version::GIT_VERSION);
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ use std::{
|
|||
|
||||
use structopt::StructOpt;
|
||||
|
||||
mod load_toml;
|
||||
|
||||
#[derive (Debug, StructOpt)]
|
||||
struct Opt {
|
||||
#[structopt (long)]
|
||||
|
@ -13,19 +15,10 @@ struct Opt {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main () -> Result <(), Box <dyn Error>> {
|
||||
use std::io::Read;
|
||||
let config_file = load_toml::load ("config/ptth_server.toml");
|
||||
|
||||
let config_file = {
|
||||
let config_file_path = "config/ptth_server.toml";
|
||||
|
||||
let mut f = std::fs::File::open (config_file_path).unwrap_or_else (|_| panic! ("Can't open {:?}", config_file_path));
|
||||
let mut buffer = vec! [0u8; 4096];
|
||||
let bytes_read = f.read (&mut buffer).unwrap_or_else (|_| panic! ("Can't read {:?}", config_file_path));
|
||||
buffer.truncate (bytes_read);
|
||||
|
||||
let config_s = String::from_utf8 (buffer).unwrap_or_else (|_| panic! ("Can't parse {:?} as UTF-8", config_file_path));
|
||||
toml::from_str (&config_s).unwrap_or_else (|_| panic! ("Can't parse {:?} as TOML", config_file_path))
|
||||
};
|
||||
|
||||
ptth::server::run_server (config_file, None).await
|
||||
ptth::server::run_server (
|
||||
config_file,
|
||||
None
|
||||
).await
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue