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
|
|
|
use std::io::{self, BufRead};
|
|
|
|
|
2024-04-11 12:17:39 +00:00
|
|
|
use crate::dem::elevation_from_coordinates;
|
2024-04-11 12:09:39 +00:00
|
|
|
|
2024-04-11 13:38:46 +00:00
|
|
|
use axum_macros::debug_handler;
|
|
|
|
use axum::{
|
|
|
|
extract::Path, http::StatusCode, routing::{get, post}, Json, Router,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
// initialize tracing
|
|
|
|
tracing_subscriber::fmt::init();
|
2024-04-11 12:09:39 +00:00
|
|
|
|
2024-04-11 13:38:46 +00:00
|
|
|
// build our application with a route
|
|
|
|
let app = Router::new()
|
|
|
|
// `GET /` goes to `root`
|
|
|
|
.route("/", get(root))
|
|
|
|
.route("/elevation/:lat/:lon", get(get_elevation));
|
|
|
|
|
|
|
|
// run our app with hyper, listening globally on port 3000
|
|
|
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
|
|
|
axum::serve(listener, app).await.unwrap();
|
|
|
|
}
|
2024-04-11 12:09:39 +00:00
|
|
|
|
2024-04-11 13:38:46 +00:00
|
|
|
// basic handler that responds with a static string
|
|
|
|
async fn root() -> &'static str {
|
|
|
|
"Hello, World!"
|
2024-04-11 12:09:39 +00:00
|
|
|
}
|
2024-04-11 13:38:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
async fn get_elevation(Path((lat, lon)): Path<(f64, f64)>) -> String{
|
|
|
|
let ele = elevation_from_coordinates(lat, lon);
|
|
|
|
format!("{ele}")
|
|
|
|
}
|
|
|
|
|