2021-06-01 00:54:55 +00:00
|
|
|
mod commands;
|
|
|
|
mod config;
|
2021-10-03 20:03:32 +00:00
|
|
|
mod context;
|
|
|
|
mod helper;
|
2021-06-01 00:54:55 +00:00
|
|
|
|
2021-10-03 20:03:32 +00:00
|
|
|
use crate::commands::command_filter;
|
2021-06-01 00:54:55 +00:00
|
|
|
use crate::config::GeoffreyAPIConfig;
|
2021-10-03 20:03:32 +00:00
|
|
|
use crate::context::Context;
|
|
|
|
use geoffrey_models::models::response::api_error::GeoffreyAPIError;
|
2021-06-01 00:54:55 +00:00
|
|
|
use std::net::SocketAddr;
|
2021-10-03 20:03:32 +00:00
|
|
|
use std::path::PathBuf;
|
2021-06-01 00:54:55 +00:00
|
|
|
use std::str::FromStr;
|
2021-10-03 20:03:32 +00:00
|
|
|
use structopt::StructOpt;
|
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, GeoffreyAPIError>;
|
2021-06-01 00:54:55 +00:00
|
|
|
|
|
|
|
#[derive(Debug, StructOpt, Clone)]
|
|
|
|
#[structopt(name = "GeoffreyAPI", about = "Geoffrey Central API")]
|
|
|
|
struct Args {
|
|
|
|
#[structopt(env = "GEOFFREY_CONFIG", parse(from_os_str))]
|
|
|
|
config: PathBuf,
|
|
|
|
}
|
2021-05-08 20:42:47 +00:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2021-06-01 00:54:55 +00:00
|
|
|
let args: Args = Args::from_args();
|
|
|
|
|
2021-10-03 20:03:32 +00:00
|
|
|
let cfg = GeoffreyAPIConfig::new(args.config.as_path()).unwrap();
|
2021-06-01 00:54:55 +00:00
|
|
|
|
|
|
|
let ctx = Context::new(cfg).unwrap();
|
|
|
|
|
|
|
|
let api = command_filter(ctx.clone());
|
2021-05-08 20:42:47 +00:00
|
|
|
|
2021-06-01 00:54:55 +00:00
|
|
|
warp::serve(api)
|
|
|
|
.run(SocketAddr::from_str(ctx.cfg.host.as_str()).unwrap())
|
2021-05-08 20:42:47 +00:00
|
|
|
.await;
|
2021-10-03 20:03:32 +00:00
|
|
|
}
|