-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
44 lines (38 loc) · 1.21 KB
/
main.rs
File metadata and controls
44 lines (38 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
mod model;
use crate::model::BinResponse;
use axum::extract::{OriginalUri, Query};
use axum::http::HeaderMap;
use axum::response::{IntoResponse, Response};
use axum::{Json, Router};
use std::collections::HashMap;
use tokio::net::TcpListener;
#[cfg(flavor = "native")]
const FLAVOR: &str = "native";
#[cfg(flavor = "embed")]
const FLAVOR: &str = "embed";
#[cfg(flavor = "runtime")]
const FLAVOR: &str = "runtime";
#[tokio::main(flavor = "current_thread")]
async fn main() {
let app = Router::new().route("/get", axum::routing::get(get));
let addr = "0.0.0.0:3000";
let tcp_listener = TcpListener::bind(addr).await.unwrap();
println!("listening on {}", addr);
axum::Server::from_tcp(tcp_listener.into_std().unwrap())
.unwrap()
.serve(app.into_make_service())
.await
.unwrap();
}
async fn get(
OriginalUri(uri): OriginalUri,
Query(params): Query<HashMap<String, String>>,
header_map: HeaderMap,
) -> Response {
let headers = header_map
.iter()
.map(|(k, v)| (k.to_string(), v.to_str().unwrap().to_string()))
.collect();
let bin_response = BinResponse::new(FLAVOR, params, headers, uri.to_string());
Json(bin_response).into_response()
}