|
@@ -5,11 +5,19 @@ mod config;
|
|
mod handler;
|
|
mod handler;
|
|
|
|
|
|
use std::env;
|
|
use std::env;
|
|
|
|
+use std::process;
|
|
use hyper::Server;
|
|
use hyper::Server;
|
|
|
|
|
|
-fn main() {
|
|
|
|
|
|
+fn actual_main() -> i32 {
|
|
let config_path = env::args().nth(1).unwrap_or("./config.json".to_string());
|
|
let config_path = env::args().nth(1).unwrap_or("./config.json".to_string());
|
|
- let cfg = config::load(&config_path);
|
|
|
|
|
|
+ println!("Loading configuration from {}", config_path);
|
|
|
|
+ let cfg = match config::load(&config_path) {
|
|
|
|
+ Ok(cfg) => cfg,
|
|
|
|
+ Err(err) => {
|
|
|
|
+ println!("Failed to load configuration: {}", err);
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
let port = cfg.port.unwrap_or(8000);
|
|
let port = cfg.port.unwrap_or(8000);
|
|
let site = handler::new(cfg);
|
|
let site = handler::new(cfg);
|
|
|
|
|
|
@@ -17,4 +25,10 @@ fn main() {
|
|
println!("Listening on {}", listen);
|
|
println!("Listening on {}", listen);
|
|
Server::http(listen.as_ref() as &str).unwrap()
|
|
Server::http(listen.as_ref() as &str).unwrap()
|
|
.handle(site).unwrap();
|
|
.handle(site).unwrap();
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+fn main() {
|
|
|
|
+ let exit_code = actual_main();
|
|
|
|
+ process::exit(exit_code);
|
|
}
|
|
}
|