创建仓库
This commit is contained in:
34
Go项目实战/00_顶层设计/一个Go项目的基本骨架.md
Normal file
34
Go项目实战/00_顶层设计/一个Go项目的基本骨架.md
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
tags: []
|
||||
date created: 星期日, 十二月 7日 2025, 11:44:41 中午
|
||||
date modified: 星期日, 十二月 7日 2025, 11:57:43 中午
|
||||
---
|
||||
|
||||
```plaintext
|
||||
your-api-project/
|
||||
├── cmd/
|
||||
│ └── server/
|
||||
│ ├── main.go # 调用 wire 注入,获取 app 实例,执行 app.Run()
|
||||
│ └── wire.go # Wire 依赖注入
|
||||
├── config/ # Viper 配置结构体
|
||||
├── internal/
|
||||
│ ├── api/ # (DTO层) 纯数据传输对象,无逻辑
|
||||
│ │ ├── request/
|
||||
│ │ └── response/
|
||||
│ ├── controller/ # (接口层) 解析 request -> 调 service -> 组装 response
|
||||
│ ├── service/ # (应用服务层) 编排业务逻辑,操作 Entity
|
||||
│ ├── repository/ # (资源层) 负责 CRUD,屏蔽数据库差异
|
||||
│ ├── entity/ # (领域层) 核心业务实体 (User, Article),带 GORM tag
|
||||
│ ├── router/ # (路由层) NewRouter() *gin.Engine
|
||||
│ └── middleware/ # Gin 中间件
|
||||
├── pkg/ # (基础设施层) 通用工具
|
||||
│ ├── app/ # 统一响应封装 (Gin Result)
|
||||
│ ├── auth/ # JWT 签发与解析
|
||||
│ ├── hasher/ # 密码加密 (Argon2 / Bcrypt)
|
||||
│ ├── logger/ # Zap 配置
|
||||
│ └── timeutil/ # 时间处理工具
|
||||
├── migrations/ # 数据库变更 SQL
|
||||
├── docs/ # Swagger
|
||||
├── go.mod
|
||||
└── Makefile
|
||||
```
|
||||
Reference in New Issue
Block a user