Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__debug*
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "api",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go"
}
]
}
76 changes: 57 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
# Activity 活动框架

## 简介
一个灵活可扩展的活动框架,支持多种活动玩法的快速开发和部署。
一个基于领域驱动设计(DDD)的活动框架,支持多种活动玩法的快速开发和部署。

## 核心特性
- 领域驱动设计:清晰的领域边界和职责划分
- 配置驱动:通过 JSON 配置文件定义活动
- 插件化设计:支持新玩法的快速接入
- 解耦设计:不依赖特定的UI框架或后端服务
- 状态管理:统一的活动状态管理机制

## 架构设计

### 领域驱动设计架构
1. 领域层(Domain Layer)
- 活动(Activity)领域
- 玩法(Game)领域
- 奖品(Prize)领域
- 参与(Participation)领域

2. 应用层(Application Layer)
- 应用服务
- DTO对象
- 领域对象转换

3. 基础设施层(Infrastructure Layer)
- 持久化实现
- 配置管理
- 公共组件

4. 接口层(Interface Layer)
- HTTP接口
- RPC接口
- 中间件

### 核心组件
1. 活动(Activity)
- 活动生命周期管理
Expand All @@ -26,6 +49,29 @@
- 统一的奖品模型
- 灵活的奖品发放机制

### 目录结构
```
.
├── api/ # 接口层
│ ├── handler/ # HTTP处理器
│ ├── middleware/ # 中间件
│ ├── service/ # 应用服务
│ └── error.go # 错误定义
├── constant/ # 常量定义
│ └── constant.go # 错误码和消息
├── models/ # 业务模型
│ ├── activity_config.go # 活动配置
│ └── game_config.go # 玩法配置
├── storage/ # 基础设施层
│ └── mysql/
│ ├── entity/ # 数据实体
│ ├── repository/ # 仓储实现
│ └── migrations/ # 数据库迁移
├── config/ # 配置管理
├── main.go # 程序入口
└── README.md # 项目文档
```

### 配置说明
活动配置示例:
```json
Expand All @@ -50,26 +96,18 @@
## 开发指南

### 新增活动类型
1. 实现 `ActivityInterface` 接口
2. 在 `NewActivityFromConfig` 中注册新活动类型
3. 创建对应的配置文件
1. 在 `models` 中定义活动配置结构
2. 在 `storage/mysql/entity` 中定义数据实体
3. 在 `storage/mysql/repository` 中实现仓储接口
4. 在 `api/service` 中实现应用服务

### 新增玩法
1. 实现 `GameInterface` 接口
2. 在 `NewGameFromConfig` 中注册新玩法
1. 在 `models` 中定义玩法配置结构
2. 实现玩法特定的业务逻辑
3. 定义玩法特定的配置结构

## 存储结构
### 错误处理
- 统一错误码定义在 `constant/constant.go`
- 错误处理工具在 `api/error.go`
- 应用层错误处理在 `api/service`

### 目录结构
```
storage/
├── mysql/
│ ├── migrations/ # 数据库迁移文件
│ │ └── 001_init_schema.sql
│ ├── models/ # GORM模型
│ │ └── activity.go
│ ├── repository/ # 仓储层
│ │ └── activity_repository.go
│ └── db.go # 数据库连接配置
```
33 changes: 33 additions & 0 deletions api/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package api

import (
_ "Activity/docs" // 导入生成的swagger文档

"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)

// @title Activity API
// @version 1.0
// @description 活动管理系统API文档
// @termsOfService http://swagger.io/terms/

// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host localhost:8080
// @BasePath /api/v1

// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization

// RegisterSwagger 注册Swagger路由
func (h *Handler) RegisterSwagger(r *gin.Engine) {
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
}
Loading