volo_boot 0.1.5

Simplifies bootstrapping for volo-grpc and volo-http services. / 简化 volo-grpc 和 volo-http 服务的启动。
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use anyhow::Result;
use http_grpc::http_grpc;
use volo_http::{
  Address, Server,
  server::route::{Router, post},
};

use crate::env_addr;

pub async fn http<T: http_grpc::Grpc + 'static>(init: impl Fn(Router) -> Router) -> Result<()> {
  let app = Router::new().route("/", post(http_grpc::<T>));
  let addr: Address = env_addr("HTTP", 3334).into();
  Server::new(init(app))
    .run(addr)
    .await
    .map_err(|e| anyhow::anyhow!(e))?;
  Ok(())
}