tina-core 0.0.2

Tina platform
Documentation
//! gRPC service

use std::any::TypeId;

use crate::tina::grpc::ApiGrpcService;

#[derive(Clone)]
/// gRPC service service
pub(crate) struct GrpcServiceServer<S: ApiGrpcService> {
    pub(crate) service: S,
    /// 无需授权的方法列表
    pub(crate) methods_no_auth: Vec<TypeId>,
    /// 开启自动事务处理的方法列表
    pub(crate) methods_auto_transaction: Vec<TypeId>,
}

impl<S: ApiGrpcService> GrpcServiceServer<S> {
    /// 构建
    pub fn new(service: S) -> Self {
        Self {
            service,
            methods_no_auth: Vec::new(),
            methods_auto_transaction: Vec::new(),
        }
    }
    /// 设置无需授权的方法
    #[allow(unused_variables)]
    pub fn with_no_auth<F, Args, R>(mut self, f: F) -> Self
    where
        F: Fn(Args) -> R + 'static,
    {
        self.methods_no_auth.push(TypeId::of::<F>());
        self
    }
    /// 设置开启自动事务处理的方法
    #[allow(unused_variables)]
    pub fn with_auto_transaction<F, Args, R>(mut self, f: F) -> Self
    where
        F: Fn(Args) -> R + 'static,
    {
        self.methods_auto_transaction.push(TypeId::of::<F>());
        self
    }
}