A full-stack Content Management System (CMS) built with Go (Gin, GORM, Casbin) for the backend and Vue 3 (Vite, TailwindCSS) for the frontend. Features robust RBAC (role-based access control), JWT authentication, and a modern, responsive UI. Project structure is inspired by nunu-go.
Note: All backend operations (build, test, migration, server start, etc.) should be run via the provided Makefile for consistency and reproducibility.
- 🔐 RBAC Authorization: Role-based access control with Casbin
- 👤 User Management: Full CRUD with role assignment
- 🔑 JWT Authentication: Secure token-based login
- 📊 RESTful API: Clean API with Gin
- 🎨 Modern UI: Vue3 + TailwindCSS
- 🗄️ Database: MySQL + GORM
Backend
- Gin (HTTP framework)
- GORM (ORM)
- Casbin (RBAC)
- JWT
- Wire (DI)
Frontend
- Vue 3
- Vite
- TailwindCSS
- Composition API
- Fetch API
.
├── api/ # API DTOs
├── cmd/ # Entrypoints (server, migration, task)
├── config/ # Config files (local.yml, prod.yml, model.conf)
├── internal/ # Main backend logic
│ ├── handler/ # HTTP handlers
│ ├── middleware/ # JWT, RBAC, CORS
│ ├── model/ # GORM models
│ ├── repository/ # Data access
│ ├── router/ # Routing
│ ├── service/ # Business logic
│ └── server/ # Server startup
├── pkg/ # Utilities (casbin, jwt, log, etc)
└── web/ # Frontend (Vue3 app)
└── src/
├── api.ts
├── components/
└── pages/
- Go 1.21+
- Node.js 18+
- MySQL 8.0+
- pnpm
- Clone repo
git clone https://github.com/plh97/golang-tutorial.git cd golang-tutorial - Install Go dependencies
go mod download
- Configure database in
config/local.yml - Run migrations (via Makefile)
make migration
- Start server (via Makefile)
Server: http://localhost:8291
make server
- Enter web directory
cd web - Install dependencies
pnpm install
- Start dev server
Frontend: http://localhost:8000
pnpm dev
Business Layer (MySQL):
- Tables: users, roles, permissions, user_roles, role_permissions
- Used for: UI, management, assignments
Access Layer (Casbin):
- Table: casbin_rule
- Format:
p, role_key, api_path, method - Used for: Fast API permission checks
Flow:
Request → JWT Middleware → RBAC Middleware (Casbin) → Handler
Permission Update:
UI → Update role_permissions (GORM) → Sync casbin_rule (Casbin)
Auth
- POST /v1/login
- GET /v1/profile
User
- POST /v1/user/list
- POST /v1/user
- PUT /v1/user
- DELETE /v1/user/:id
Role
- GET /v1/role/list
- POST /v1/role
- PUT /v1/role
- DELETE /v1/role/:id
Permission
- GET /v1/permission/list
- Username: [email protected]
- Password: admin123
- Role: Administrator
The project uses a Makefile as the main entrypoint for backend operations. Common targets:
make build# Build the backend binarymake test# Run backend tests with coveragemake migration# Run database migrationsmake server# Start the backend servermake docker# Build and run the backend in Dockermake swag# Generate Swagger docs
Wire dependencies
cd cmd/server/wire
wireRun tests
make testBuild
make build
# Frontend
cd web && pnpm buildMIT License
基于 Go (Gin, GORM, Casbin) 后端和 Vue3 (Vite, TailwindCSS) 前端的全栈内容管理系统。支持 RBAC 权限、JWT 登录、现代响应式 UI。项目结构参考 nunu-go。
注意: 所有后端操作(构建、测试、迁移、启动等)请通过项目根目录的 Makefile 执行,确保一致性和可复现性。
- 🔐 RBAC 权限控制:基于 Casbin 的角色访问控制
- 👤 用户管理:完整的用户增删改查及角色分配
- 🔑 JWT 认证:安全的令牌登录
- 📊 RESTful API:Gin 框架
- 🎨 现代 UI:Vue3 + TailwindCSS
- 🗄️ 数据库:MySQL + GORM
后端
- Gin (HTTP 框架)
- GORM (ORM)
- Casbin (RBAC)
- JWT
- Wire (依赖注入)
前端
- Vue 3
- Vite
- TailwindCSS
- Composition API
- Fetch API
.
├── api/ # API 定义和 DTO
├── cmd/ # 启动入口(server, migration, task)
├── config/ # 配置文件(local.yml, prod.yml, model.conf)
├── internal/ # 后端主逻辑
│ ├── handler/ # HTTP 处理器
│ ├── middleware/ # JWT、RBAC、CORS
│ ├── model/ # GORM 模型
│ ├── repository/ # 数据访问
│ ├── router/ # 路由
│ ├── service/ # 业务逻辑
│ └── server/ # 启动
├── pkg/ # 工具包(casbin, jwt, log 等)
└── web/ # 前端(Vue3 应用)
└── src/
├── api.ts
├── components/
└── pages/
- Go 1.21+
- Node.js 18+
- MySQL 8.0+
- pnpm
- 克隆仓库
git clone https://github.com/plh97/golang-tutorial.git cd golang-tutorial - 安装 Go 依赖
go mod download
- 配置数据库
config/local.yml - 运行迁移(通过 Makefile)
make migration
- 启动服务(通过 Makefile)
地址: http://localhost:8291
make server
- 进入 web 目录
cd web - 安装依赖
pnpm install
- 启动开发服务器
地址: http://localhost:8000
pnpm dev
业务层(MySQL)
- 表:users, roles, permissions, user_roles, role_permissions
- 用于:UI、管理、分配
访问层(Casbin)
- 表:casbin_rule
- 格式:
p, role_key, api_path, method - 用于:API 权限快速校验
流程:
请求 → JWT 中间件 → RBAC 中间件(Casbin)→ 处理器
权限更新:
UI → 更新 role_permissions(GORM)→ 同步 casbin_rule(Casbin)
认证
- POST /v1/login
- GET /v1/profile
用户
- POST /v1/user/list
- POST /v1/user
- PUT /v1/user
- DELETE /v1/user/:id
角色
- GET /v1/role/list
- POST /v1/role
- PUT /v1/role
- DELETE /v1/role/:id
权限
- GET /v1/permission/list
- 用户名:[email protected]
- 密码:admin123
- 角色:管理员
本项目后端操作统一通过 Makefile 入口。常用命令:
make build# 构建后端二进制make test# 运行后端测试并生成覆盖率make migration# 执行数据库迁移make server# 启动后端服务make docker# Docker 构建和运行make swag# 生成 Swagger 文档
生成 Wire 依赖
cd cmd/server/wire
wire运行测试
make test构建
make build
# 前端
cd web && pnpm buildMIT License