2020-11-01 03:17:11 +00:00
|
|
|
use std::{
|
|
|
|
error::Error,
|
|
|
|
path::PathBuf,
|
|
|
|
};
|
|
|
|
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
|
|
|
#[derive (Debug, StructOpt)]
|
|
|
|
struct Opt {
|
|
|
|
#[structopt (long)]
|
|
|
|
file_server_root: Option <PathBuf>,
|
|
|
|
}
|
2020-10-30 22:53:03 +00:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main () -> Result <(), Box <dyn Error>> {
|
2020-11-02 03:34:50 +00:00
|
|
|
use std::io::Read;
|
|
|
|
|
2020-11-02 13:37:08 +00:00
|
|
|
let config_file = {
|
2020-11-02 19:17:22 +00:00
|
|
|
let config_file_path = "config/ptth_server.toml";
|
2020-11-02 13:37:08 +00:00
|
|
|
|
2020-11-06 03:35:55 +00:00
|
|
|
let mut f = std::fs::File::open (config_file_path).unwrap_or_else (|_| panic! ("Can't open {:?}", config_file_path));
|
2020-11-02 13:37:08 +00:00
|
|
|
let mut buffer = vec! [0u8; 4096];
|
2020-11-06 03:35:55 +00:00
|
|
|
let bytes_read = f.read (&mut buffer).unwrap_or_else (|_| panic! ("Can't read {:?}", config_file_path));
|
2020-11-02 13:37:08 +00:00
|
|
|
buffer.truncate (bytes_read);
|
|
|
|
|
2020-11-06 03:35:55 +00:00
|
|
|
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))
|
2020-11-02 13:37:08 +00:00
|
|
|
};
|
2020-11-02 03:34:50 +00:00
|
|
|
|
2020-11-06 03:44:32 +00:00
|
|
|
ptth::server::run_server (config_file, None).await
|
2020-10-30 22:53:03 +00:00
|
|
|
}
|