allframe_core/grpc/
mod.rs

1//! gRPC Server Infrastructure
2//!
3//! This module provides a fluent builder API for configuring and running
4//! gRPC servers with support for:
5//!
6//! - TLS/mTLS encryption
7//! - gRPC reflection (service discovery)
8//! - Health checking
9//! - Graceful shutdown
10//!
11//! # Quick Start
12//!
13//! ```rust,ignore
14//! use allframe_core::grpc::GrpcServer;
15//! use allframe_core::shutdown::GracefulShutdown;
16//!
17//! // Simple server
18//! GrpcServer::builder()
19//!     .addr("[::1]:50051")
20//!     .serve(my_service)
21//!     .await?;
22//!
23//! // Full-featured server
24//! let shutdown = GracefulShutdown::new();
25//!
26//! GrpcServer::builder()
27//!     .addr("0.0.0.0:50051")
28//!     .reflection(FILE_DESCRIPTOR_SET)
29//!     .health_check()
30//!     .tls_from_env()
31//!     .graceful_shutdown(shutdown)
32//!     .serve(my_service)
33//!     .await?;
34//! ```
35//!
36//! # TLS Configuration
37//!
38//! TLS can be configured either directly or from environment variables:
39//!
40//! ```rust,ignore
41//! use allframe_core::grpc::{GrpcServer, TlsConfig};
42//!
43//! // Direct configuration
44//! let tls = TlsConfig::new("cert.pem", "key.pem")
45//!     .with_client_ca("ca.pem"); // For mTLS
46//!
47//! GrpcServer::builder()
48//!     .tls(tls)
49//!     .serve(my_service)
50//!     .await?;
51//!
52//! // From environment variables
53//! // GRPC_TLS_CERT, GRPC_TLS_KEY, GRPC_TLS_CLIENT_CA
54//! GrpcServer::builder()
55//!     .tls_from_env()
56//!     .serve(my_service)
57//!     .await?;
58//! ```
59//!
60//! # gRPC Reflection
61//!
62//! Enable service discovery with gRPC reflection:
63//!
64//! ```rust,ignore
65//! // Include the file descriptor set from your build
66//! pub const FILE_DESCRIPTOR_SET: &[u8] =
67//!     include_bytes!(concat!(env!("OUT_DIR"), "/proto_descriptor.bin"));
68//!
69//! GrpcServer::builder()
70//!     .reflection(FILE_DESCRIPTOR_SET)
71//!     .serve(my_service)
72//!     .await?;
73//! ```
74//!
75//! # Health Checking
76//!
77//! Enable the standard gRPC health checking protocol:
78//!
79//! ```rust,ignore
80//! GrpcServer::builder()
81//!     .health_check()
82//!     .serve(my_service)
83//!     .await?;
84//! ```
85
86mod server;
87mod tls;
88
89pub use server::{GrpcServer, GrpcServerBuilder, GrpcServerError};
90pub use tls::{TlsConfig, TlsError};