Files
Inbox/Go项目实战/00_顶层设计/一个Go项目的基本骨架.md
2025-12-11 07:24:36 +08:00

35 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
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
```