| Crates.io | mockforge-grpc |
| lib.rs | mockforge-grpc |
| version | 0.3.31 |
| created_at | 2025-10-16 21:32:17.402887+00 |
| updated_at | 2026-01-04 23:38:20.044127+00 |
| description | gRPC protocol support for MockForge |
| homepage | https://mockforge.dev |
| repository | https://github.com/SaaSy-Solutions/mockforge |
| max_upload_size | |
| id | 1886795 |
| size | 724,502 |
Flexible gRPC mocking and service discovery for MockForge.
.proto files from configurable directoriesuse mockforge_grpc::{start, DynamicGrpcConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// Start with default configuration
start(50051).await?;
Ok(())
}
use mockforge_grpc::{start_with_latency_and_config, DynamicGrpcConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let config = DynamicGrpcConfig {
proto_dir: "my-protos".to_string(),
enable_reflection: true,
excluded_services: vec!["grpc.reflection.v1alpha.ServerReflection".to_string()],
};
start_with_latency_and_config(50051, None, Some(config)).await?;
Ok(())
}
MOCKFORGE_PROTO_DIR: Directory containing .proto files (default: proto/)MOCKFORGE_GRPC_PORT: gRPC server port (default: 50051)The build system automatically discovers all .proto files in the configured directory and subdirectories. This means:
your-project/
├── proto/ # Default proto directory
│ ├── service1.proto # Will be discovered
│ ├── service2.proto # Will be discovered
│ └── subdir/
│ └── service3.proto # Will be discovered
├── src/
└── Cargo.toml
Set the MOCKFORGE_PROTO_DIR environment variable to use a different directory:
export MOCKFORGE_PROTO_DIR="my-custom-protos"
cargo build
See the examples/ directory for complete examples:
flexible_grpc.rs: Demonstrates dynamic service discoveryreflection_example.rs: Shows how to use gRPC reflectionIf you're migrating from the old hardcoded approach:
build.rsMOCKFORGE_PROTO_DIR to point to your proto filesDynamicGrpcConfig for advanced configurationuse mockforge_grpc::{DynamicGrpcConfig, ServiceRegistry, ServiceImplementation};
// Create custom service implementations
struct MyCustomService {
name: String,
}
impl ServiceImplementation for MyCustomService {
// Implement your custom service logic
}
// Register services dynamically
let mut registry = ServiceRegistry::new();
registry.register("my.service.Service".to_string(), MyCustomService::new());
If you see "No .proto files found", check:
MOCKFORGE_PROTO_DIR environment variable.proto filesIf proto compilation fails:
.proto files are validIf services aren't being discovered: