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 16 : async fn status_handler(_: Request<Body>) -> Result<Response<Body>, ApiError> {
8 16 : json_response(StatusCode::OK, "")
9 16 : }
10 :
11 16 : fn make_router() -> RouterBuilder<hyper::Body, ApiError> {
12 16 : endpoint::make_router().get("/v1/status", status_handler)
13 16 : }
14 :
15 16 : pub async fn task_main(http_listener: TcpListener) -> anyhow::Result<Infallible> {
16 16 : scopeguard::defer! {
17 16 : info!("http has shut down");
18 16 : }
19 16 :
20 16 : let service = || RouterService::new(make_router().build()?);
21 16 :
22 16 : hyper::Server::from_tcp(http_listener)?
23 16 : .serve(service().map_err(|e| anyhow!(e))?)
24 17 : .await?;
25 :
26 UBC 0 : bail!("hyper server without shutdown handling cannot shutdown successfully");
27 0 : }
|