1use std::convert::Infallible;
5use tonic::server::NamedService;
6use tower::Service;
7
8pub mod alpha;
9pub mod v2;
10
11pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
12
13#[derive(Default)]
14pub struct Services {
15 router: axum::Router,
16}
17
18impl Services {
19 pub fn new() -> Self {
20 Self::default()
21 }
22
23 pub fn add_service<S>(mut self, svc: S) -> Self
25 where
26 S: Service<
27 axum::extract::Request,
28 Response: axum::response::IntoResponse,
29 Error = Infallible,
30 > + NamedService
31 + Clone
32 + Send
33 + Sync
34 + 'static,
35 S::Future: Send + 'static,
36 S::Error: Into<BoxError> + Send,
37 {
38 self.router = self
39 .router
40 .route_service(&format!("/{}/{{*rest}}", S::NAME), svc);
41 self
42 }
43
44 pub fn into_router(self) -> axum::Router {
45 self.router.layer(tonic_web::GrpcWebLayer::new())
46 }
47}