# dukang **Repository Path**: javaerxue/dukang ## Basic Information - **Project Name**: dukang - **Description**: 何以解忧,唯有杜康! - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-06 - **Last Updated**: 2026-05-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Based on the provided code map, I can see this is a Go-based business flow framework called "Dukang" (都可能). Let me analyze the project structure and create a comprehensive README. --- # Dukang 业务流程框架 [English Documentation](#english) ## 项目简介 Dukang 是一个基于 Go 语言开发的业务流程编排框架,主要用于处理订单确认等业务场景的流程调度。该框架采用配置驱动的设计模式,通过定义好的步骤(Step)和传输器(Transport)来实现业务流程的灵活配置和执行。 核心特性: - **配置驱动**:通过 JSON 配置文件定义业务场景和步骤 - **传输器模式**:支持多种传输器(Base、Taxi 等)来处理不同的业务场景 - **运行时管理**:提供运行时上下文来存储和管理流程执行状态 - **注册机制**:灵活的传输器注册系统,便于扩展 ## 项目结构 ``` dukang/ ├── biz/ │ ├── dal/ # 数据访问层 │ │ └── test_dal.go │ ├── dukang/ # 核心业务逻辑 │ │ ├── ability/ │ │ │ └── common/ │ │ │ └── pay/ │ │ │ └── payComponent.go # 支付组件 │ │ ├── config/ # 配置文件 │ │ │ ├── confirm_order.json │ │ │ └── confirm_order2.json │ │ ├── inputsource/ # 输入源 │ │ │ └── confirm_order.go │ │ ├── main.go # 主入口 │ │ ├── model/ # 数据模型 │ │ │ └── order/ │ │ │ └── order.go │ │ ├── service/ # 服务层 │ │ │ └── service.go │ │ ├── stepruntime/ # 步骤运行时 │ │ │ └── confirm_order.go │ │ └── transport/ # 传输器 │ │ ├── base/ # 基础传输器 │ │ │ └── transport.go │ │ └── taxi/ # 出租车传输器 │ │ └── transport.go │ └── └── framework/ # 框架核心 ├── bizdukang/ # 框架加载模块 │ ├── load.go │ └── load_test.go ├── config/ # 配置定义 │ └── config.go ├── doc.go ├── errors/ # 错误处理 │ └── errors.go ├── flow/ # 流程接口定义 │ ├── contracts.go │ └── func_factor.go ├── registry/ # 注册表 │ └── registry.go ├── runner/ # 运行器 │ └── run.go └── scheduler/ # 调度器 ├── bootstrap.go ├── invoke.go ├── invoke_test.go ├── scheduler.go ├── scheduler_test.go ├── validate.go └── validate_test.go ``` ## 核心概念 ### 1. 传输器 (Transport) 传输器是执行具体业务步骤的对象,每个传输器实现了特定的业务逻辑: - `ConfirmOrderBaseTransport` - 基础订单确认传输器 - `ConfirmOrderTaxiTransport` -出租车订单确认传输器 每个传输器需要实现两个核心步骤: - `FetchInfoStep` - 获取信息步骤 - `BuildResponseStep` - 构建响应步骤 ### 2. 运行时 (Runtime) 运行时用于在流程执行过程中存储和传递数据: ```go type ConfirmOrderStepRuntime struct { // 运行时上下文数据 } ``` ### 3. 配置 (Config) 通过 JSON 配置文件定义业务场景: ```json { "scenarios": { "confirm_order": { "steps": ["FetchInfo", "BuildResponse"] } } } ``` ### 4. 注册表 (Registry) 用于注册和管理传输器: ```go reg := registry.New() reg.MustRegister("base", NewConfirmOrderBaseTransport()) reg.MustRegister("paywall", NewConfirmOrderTaxiTransport()) ``` ## 快速开始 ### 安装 ```bash go mod tidy ``` ### 运行示例 ```bash go run biz/dukang/main.go ``` ### 编写新的传输器 ```go type MyTransport struct{} func New() *MyTransport { return &MyTransport{} } func (*MyTransport) FetchInfoStep(ctx context.Context, rt *stepruntime.ConfirmOrderStepRuntime) error { // 实现获取信息逻辑 return nil } func (*MyTransport) BuildResponseStep(ctx context.Context, rt *stepruntime.ConfirmOrderStepRuntime) error { // 实现构建响应逻辑 return nil } ``` ### 注册传输器 ```go reg := registry.New() reg.MustRegister("my_transport", New()) ``` ## 配置说明 配置文件 `biz/dukang/config/confirm_order.json` 示例: ```json { "scenarios": { "confirm_order": { "transport": "base", "steps": [ { "id": "FetchInfo", "method": "FetchInfoStep" }, { "id": "BuildResponse", "method": "BuildResponseStep" } ] } } } ``` ## 测试 ```bash go test ./... ``` ## 框架 API ### 框架核心函数 - `runner.Run()` - 运行配置好的流程 - `scheduler.Bootstrap()` - 初始化调度器 - `scheduler.InvokeTransportStep()` - 调用传输器的步骤方法 - `registry.Registry` - 传输器注册表 ### 配置加载 ```go // 从文件加载配置 config, err := bizdukang.LoadFile("config.json") // 从字节加载 config, err := bizdukang.LoadBytes(data) // 从 Reader 加载 config, err := bizdukang.LoadReader(reader) ``` --- ## 贡献指南 欢迎提交 Issue 和 Pull Request! ## 许可证 本项目仅供学习交流使用。 --- # English ## Overview Dukang is a Go-based business flow orchestration framework designed for handling business scenarios like order confirmation. It uses a configuration-driven approach to define flows through Steps and Transports. ## Key Features - **Configuration-driven**: Define business scenarios via JSON config files - **Transport pattern**: Support multiple transports (Base, Taxi, etc.) for different scenarios - **Runtime management**: Manage flow execution state through runtime context - **Registry system**: Flexible transport registration for extensibility ## Getting Started ```bash go mod tidy go run biz/dukang/main.go ``` ## Quick Example ```go reg := registry.New() reg.MustRegister("base", NewConfirmOrderBaseTransport()) reg.MustRegister("paywall", NewConfirmOrderTaxiTransport()) err := runner.Run(ctx, "confirm_order.json", inputSource, runtime, reg) ``` ## License For learning and communication purposes only.