2024-04-11 12:09:39 +00:00
|
|
|
|
2024-04-11 12:17:39 +00:00
|
|
|
mod dem;
|
2024-04-11 13:38:46 +00:00
|
|
|
|
2024-04-11 12:09:39 +00:00
|
|
|
|
2024-04-11 22:33:10 +00:00
|
|
|
use std::env;
|
2024-04-11 13:38:46 +00:00
|
|
|
use axum_macros::debug_handler;
|
|
|
|
use axum::{
|
2024-04-11 22:33:10 +00:00
|
|
|
extract::{Path, State}, routing::{get}, Router
|
2024-04-11 13:38:46 +00:00
|
|
|
};
|
2024-04-11 22:33:10 +00:00
|
|
|
use dem::{DSC, new_cache};
|
2024-04-11 13:38:46 +00:00
|
|
|
|
2024-04-11 22:33:10 +00:00
|
|
|
use tracing::info;
|
2024-04-11 18:10:53 +00:00
|
|
|
|
|
|
|
|
2024-04-11 18:34:55 +00:00
|
|
|
|
2024-04-11 18:10:53 +00:00
|
|
|
#[tokio::main(flavor = "current_thread")]
|
2024-04-11 13:38:46 +00:00
|
|
|
async fn main() {
|
|
|
|
// initialize tracing
|
|
|
|
tracing_subscriber::fmt::init();
|
2024-04-11 12:09:39 +00:00
|
|
|
|
2024-04-11 18:10:53 +00:00
|
|
|
|
2024-04-11 22:33:10 +00:00
|
|
|
let cache = new_cache(1000);
|
2024-04-11 18:10:53 +00:00
|
|
|
|
2024-04-11 13:38:46 +00:00
|
|
|
// build our application with a route
|
|
|
|
let app = Router::new()
|
2024-04-11 18:10:53 +00:00
|
|
|
.route("/elevation/:lat/:lon", get(get_elevation))
|
2024-04-11 18:34:55 +00:00
|
|
|
.with_state(cache);
|
2024-04-11 13:38:46 +00:00
|
|
|
|
2024-04-11 12:09:39 +00:00
|
|
|
|
2024-04-11 22:33:10 +00:00
|
|
|
let port = env::var("HTTP_PORT").unwrap_or("3000".to_string());
|
|
|
|
let host = format!("[::]:{port}");
|
|
|
|
info!("Will start server on {host}");
|
|
|
|
|
|
|
|
|
|
|
|
let listener = tokio::net::TcpListener::bind(host).await.unwrap();
|
|
|
|
axum::serve(listener, app).await.unwrap();
|
2024-04-11 12:09:39 +00:00
|
|
|
}
|
2024-04-11 13:38:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
#[debug_handler]
|
2024-04-11 18:34:55 +00:00
|
|
|
async fn get_elevation(State(shared): State<DSC>, Path((lat, lon)): Path<(f64, f64)>) -> String{
|
2024-04-11 18:10:53 +00:00
|
|
|
|
|
|
|
let ele = dem::elevation_from_coordinates(shared, lat, lon);
|
|
|
|
let myele = ele.await;
|
2024-04-11 22:33:10 +00:00
|
|
|
format!("{myele}")
|
2024-04-11 13:38:46 +00:00
|
|
|
}
|
|
|
|
|