mod config; mod error; mod grib2; mod nexrad; mod tiles; use crate::config::Config; use crate::grib2::{Grib2DataCache, Grib2TileCache, grib2_handler}; use crate::nexrad::{NexradDataCache, NexradTileCache, nexrad_handler}; use crate::tiles::{DataId, TileId}; use axum::Router; use axum::routing::get; use moka::future::Cache; use std::env::args; use std::fmt::{Debug, Formatter}; use std::sync::Arc; use tracing_subscriber::fmt::format::FmtSpan; use tracing_subscriber::util::SubscriberInitExt; use wxbox_grib2::GribMessage; #[derive(Clone)] pub struct AppState { grib2_data_cache: Grib2DataCache, grib2_tile_cache: Grib2TileCache, nexrad_data_cache: NexradDataCache, nexrad_tile_cache: NexradTileCache, config: Arc, } impl Debug for AppState { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "") } } #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::fmt() .with_span_events(FmtSpan::CLOSE) .init(); let config_file = args().nth(1).expect("usage: wxbox-tiler config.toml"); let config_str = tokio::fs::read_to_string(config_file).await?; let config: Config = toml::from_str(&config_str)?; let grib2_data_cache: Grib2DataCache = Cache::new(10_000); let grib2_tile_cache: Grib2TileCache = Cache::new(10_000); let nexrad_data_cache: NexradDataCache = Cache::new(10_000); let nexrad_tile_cache: NexradTileCache = Cache::new(10_000); let state = AppState { grib2_tile_cache, grib2_data_cache, nexrad_tile_cache, nexrad_data_cache, config: Arc::new(config), }; let app = Router::new() .route("/grib2/{source}/{z}/{x}/{y}", get(grib2_handler)) .route("/nexrad/{source}/{z}/{x}/{y}", get(nexrad_handler)) .with_state(state); let listener = tokio::net::TcpListener::bind("[::]:3000").await?; axum::serve(listener, app).await?; Ok(()) }