Geoffrey-rs/geoffrey_api/src/main.rs

38 lines
928 B
Rust
Raw Normal View History

mod commands;
mod config;
mod context;
mod helper;
use crate::commands::command_filter;
use crate::config::GeoffreyAPIConfig;
use crate::context::Context;
use geoffrey_models::models::response::api_error::GeoffreyAPIError;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::str::FromStr;
use structopt::StructOpt;
pub type Result<T> = std::result::Result<T, GeoffreyAPIError>;
#[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() {
let args: Args = Args::from_args();
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;
}