Skip to main content

servers/
configurator.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::sync::Arc;
16
17use common_error::ext::BoxedError;
18use tonic::transport::server::Router as GrpcRouter;
19
20use crate::grpc::builder::GrpcServerBuilder;
21
22/// A configurator that customizes or enhances a gRPC router.
23#[async_trait::async_trait]
24pub trait GrpcRouterConfigurator<C>: Send + Sync {
25    /// Configures the given gRPC router using the provided context.
26    async fn configure_grpc_router(
27        &self,
28        route: GrpcRouter,
29        ctx: C,
30    ) -> std::result::Result<GrpcRouter, BoxedError>;
31}
32
33pub type GrpcRouterConfiguratorRef<C> = Arc<dyn GrpcRouterConfigurator<C>>;
34
35/// A configurator that customizes or enhances a [`GrpcServerBuilder`].
36#[async_trait::async_trait]
37pub trait GrpcBuilderConfigurator<C>: Send + Sync {
38    async fn configure(
39        &self,
40        builder: GrpcServerBuilder,
41        ctx: C,
42    ) -> std::result::Result<GrpcServerBuilder, BoxedError>;
43}
44
45pub type GrpcBuilderConfiguratorRef<C> = Arc<dyn GrpcBuilderConfigurator<C>>;