# Go DDD框架 **Repository Path**: aesoper/cde ## Basic Information - **Project Name**: Go DDD框架 - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-23 - **Last Updated**: 2025-01-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # CDE (Command-Driven Engine) ## Overview CDE (Command-Driven Engine) is a robust, flexible, and extensible Go framework designed to simplify complex application architectures by providing a clean, modular approach to handling commands, events, and queries. ## Features ### Core Concepts - **Command Handling**: A powerful mechanism for processing commands with middleware support - **Event Handling**: Flexible event management with advanced routing and matching - **Query Handling**: Efficient query processing with middleware integration - **Middleware Support**: - Logging - Tracing (OpenTelemetry) - Metrics - Error Recovery ### Key Components - `CommandHandler`: Process domain commands with comprehensive middleware - `EventHandler`: Manage and route domain events - `QueryHandler`: Handle read operations with middleware support ## Installation ```bash go get gitee.com/aesoper/cde ``` ## Quick Start ### Command Handling ```go package main import ( "context" "gitee.com/aesoper/cde" "gitee.com/aesoper/cde/middleware/commandhandler/logger" "gitee.com/aesoper/cde/middleware/commandhandler/tracer" ) type CreateUserCommand struct { Username string Email string } func (c *CreateUserCommand) CommandType() cde.CommandType { return "create_user" } func (c *CreateUserCommand) Validate() error { // Add validation logic return nil } type UserCommandHandler struct{} func (h *UserCommandHandler) Handle(ctx context.Context, cmd cde.Command) error { userCmd := cmd.(*CreateUserCommand) // Implement user creation logic return nil } func main() { handler := &UserCommandHandler{} middleware := cde.NewCommandHandlerBuilder(handler). Use(logger.LoggerMiddleware()). Use(tracer.TracerMiddleware()). Build() cmd := &CreateUserCommand{ Username: "johndoe", Email: "john@example.com", } err := middleware.Handle(context.Background(), cmd) if err != nil { // Handle error } } ``` ## Middleware ### Logger Middleware - Configurable logging for command processing - Tracks command type, duration, and status ### Tracer Middleware - OpenTelemetry integration - Detailed span tracking for commands - Error recording ### Metrics Middleware - Performance metrics collection - Command processing duration tracking - Error rate monitoring ## Configuration ### Middleware Options Each middleware supports configuration: ```go // Example: Configuring Logger Middleware loggerMiddleware := logger.LoggerMiddleware( logger.WithEnable(true), logger.WithLoggerName("custom_logger"), ) // Example: Configuring Tracer Middleware tracerMiddleware := tracer.TracerMiddleware( tracer.WithEnable(true), tracer.WithTracerName("custom_tracer"), ) ``` ## Performance - Lightweight and minimal overhead - Designed for high-performance scenarios - Supports concurrent processing ## Contributing 1. Fork the repository 2. Create your feature branch (`git checkout -b feature/AmazingFeature`) 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) 4. Push to the branch (`git push origin feature/AmazingFeature`) 5. Open a Pull Request ## License Distributed under the Apache License 2.0. See `LICENSE` for more information. ## Contact Project Link: [https://gitee.com/aesoper/cde](https://gitee.com/aesoper/cde)