TLA Line data Source code
1 : use anyhow::{anyhow, bail};
2 : use hyper::{Body, Request, Response, StatusCode};
3 : use std::{convert::Infallible, net::TcpListener};
4 : use tracing::info;
5 : use utils::http::{endpoint, error::ApiError, json::json_response, RouterBuilder, RouterService};
6 :
7 CBC 22 : async fn status_handler(_: Request<Body>) -> Result<Response<Body>, ApiError> {
8 22 : json_response(StatusCode::OK, "")
9 22 : }
10 :
11 22 : fn make_router() -> RouterBuilder<hyper::Body, ApiError> {
12 22 : endpoint::make_router().get("/v1/status", status_handler)
13 22 : }
14 :
15 22 : pub async fn task_main(http_listener: TcpListener) -> anyhow::Result<Infallible> {
16 22 : scopeguard::defer! {
17 22 : info!("http has shut down");
18 22 : }
19 22 :
20 22 : let service = || RouterService::new(make_router().build()?);
21 22 :
22 22 : hyper::Server::from_tcp(http_listener)?
23 22 : .serve(service().map_err(|e| anyhow!(e))?)
24 23 : .await?;
25 :
26 UBC 0 : bail!("hyper server without shutdown handling cannot shutdown successfully");
27 0 : }
|