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;
|
use tokio::sync::oneshot;
|
||||||
|
|
||||||
|
mod load_toml;
|
||||||
|
|
||||||
use ptth::relay;
|
use ptth::relay;
|
||||||
use ptth::relay::RelayState;
|
use ptth::relay::RelayState;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main () -> Result <(), Box <dyn Error>> {
|
async fn main () -> Result <(), Box <dyn Error>> {
|
||||||
use std::io::Read;
|
let config_file = load_toml::load ("config/ptth_relay.toml");
|
||||||
|
|
||||||
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))
|
|
||||||
};
|
|
||||||
|
|
||||||
eprintln! ("ptth_relay Git version: {:?}", ptth::git_version::GIT_VERSION);
|
eprintln! ("ptth_relay Git version: {:?}", ptth::git_version::GIT_VERSION);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ use std::{
|
||||||
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
mod load_toml;
|
||||||
|
|
||||||
#[derive (Debug, StructOpt)]
|
#[derive (Debug, StructOpt)]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
#[structopt (long)]
|
#[structopt (long)]
|
||||||
|
@ -13,19 +15,10 @@ struct Opt {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main () -> Result <(), Box <dyn Error>> {
|
async fn main () -> Result <(), Box <dyn Error>> {
|
||||||
use std::io::Read;
|
let config_file = load_toml::load ("config/ptth_server.toml");
|
||||||
|
|
||||||
let config_file = {
|
ptth::server::run_server (
|
||||||
let config_file_path = "config/ptth_server.toml";
|
config_file,
|
||||||
|
None
|
||||||
let mut f = std::fs::File::open (config_file_path).unwrap_or_else (|_| panic! ("Can't open {:?}", config_file_path));
|
).await
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ use hyper::{
|
||||||
};
|
};
|
||||||
use hyper::service::{make_service_fn, service_fn};
|
use hyper::service::{make_service_fn, service_fn};
|
||||||
use serde::{
|
use serde::{
|
||||||
Deserialize,
|
Deserialize,
|
||||||
Serialize,
|
Serialize,
|
||||||
};
|
};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
|
|
Loading…
Reference in New Issue