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