diff --git a/geoffrey_api/src/main.rs b/geoffrey_api/src/main.rs index 8b6702a..e4f948a 100644 --- a/geoffrey_api/src/main.rs +++ b/geoffrey_api/src/main.rs @@ -1,12 +1,35 @@ -use warp::Filter; +mod commands; +mod error; +mod context; +mod config; +mod responses; + +use structopt::StructOpt; +use std::path::PathBuf; +use crate::config::GeoffreyAPIConfig; +use std::net::SocketAddr; +use std::str::FromStr; +use crate::context::Context; +use crate::commands::command_filter; + +#[derive(Debug, StructOpt, Clone)] +#[structopt(name = "GeoffreyAPI", about = "Geoffrey Central API")] +struct Args { + #[structopt(env = "GEOFFREY_CONFIG", parse(from_os_str))] + config: PathBuf, +} #[tokio::main] async fn main() { - // GET /hello/warp => 200 OK with body "Hello, warp!" - let hello = warp::path!("hello" / String) - .map(|name| format!("Hello, {}!", name)); + let args: Args = Args::from_args(); - warp::serve(hello) - .run(([127, 0, 0, 1], 3030)) + let cfg= GeoffreyAPIConfig::new(args.config.as_path()).unwrap(); + + let ctx = Context::new(cfg).unwrap(); + + let api = command_filter(ctx.clone()); + + warp::serve(api) + .run(SocketAddr::from_str(ctx.cfg.host.as_str()).unwrap()) .await; } \ No newline at end of file