mod commands; mod config; mod context; mod helper; mod logging; use crate::commands::command_filter; use crate::config::GeoffreyAPIConfig; use crate::context::Context; use crate::logging::{init_logging, LogLevel}; 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 = std::result::Result; #[derive(Debug, StructOpt, Clone)] #[structopt(name = "GeoffreyAPI", about = "Geoffrey Central API")] struct Args { #[structopt(env = "GEOFFREY_CONFIG", parse(from_os_str))] config: PathBuf, #[structopt( short, long, env = "GEOFFREY_LOG_LEVEL", parse(from_str), default_value = "Info" )] log_level: LogLevel, } #[tokio::main] async fn main() { let args: Args = Args::from_args(); if let Err(e) = init_logging(args.log_level) { println!("Unable to initialize logger: {}", e); return; } let cfg = match GeoffreyAPIConfig::new(args.config.as_path()) { Ok(cfg) => cfg, Err(e) => { log::warn!("Error opening config: {}", e); return; } }; let socket_addr = match SocketAddr::from_str(cfg.host.as_str()) { Ok(socket_addr) => socket_addr, Err(e) => { log::warn!("Error parsing {} as address: {}", cfg.host, e); return; } }; let ctx = Context::new(cfg).unwrap(); let api = command_filter(ctx.clone()); warp::serve(api).run(socket_addr).await; }