1use axum::extract::Path;
2use axum::{Router, middleware, routing::get};
3use std::net::{IpAddr, Ipv4Addr, SocketAddr};
4use std::time;
5
6mod unlock;
7
8#[tokio::main]
9async fn main() {
10 let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 7878);
11 let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
12 println!("listening on {}", addr);
13
14 let now = time::Instant::now();
15 let daily = time::Duration::from_secs(24 * 60 * 60);
16 let state = unlock::Unlock::new(now, daily);
17
18 let app =
19 Router::new()
20 .route("/day/{id}", get(handler))
21 .route_layer(middleware::from_fn_with_state(
22 state.clone(),
23 unlock::unlock,
24 ));
25
26 axum::serve(listener, app).await.unwrap();
27}
28
29async fn handler(Path(id): Path<u32>) -> String {
30 format!("hello day {id}")
31}