littlebot
Published on 2025-04-09 / 0 Visits
0

【源码】基于Go语言的RBAC权限管理脚手架

项目简介

本项目 omgind 是在 gin-admin 基础上,依据个人喜好进行魔改的后台工程模板。它基于 GIN + entgo + CASBIN + WIRE 实现了 RBAC 权限管理,为开发者提供一套轻量的中后台开发框架,能帮助快速完成业务需求开发。

项目的主要特性和功能

  1. 设计规范:遵循 RESTful API 设计规范和基于接口的编程规范。
  2. 框架支持:基于 GIN 框架,拥有 JWTAuth、CORS 等丰富中间件。
  3. 权限控制:采用 Casbin 的 RBAC 访问控制模型,可对按钮和接口进行细粒度控制。
  4. 数据库存储:使用 entgo 进行数据库存储。
  5. 依赖注入:借助 WIRE 实现依赖注入,简化模块初始化。
  6. 日志输出:基于 Logrus & Context 实现日志输出,结合 Context 输出关键字段,支持日志钩子写入 Gorm。
  7. 用户认证:基于 JWT 进行用户认证,具备黑名单验证机制。
  8. 文档生成:通过 Swaggo 自动生成 Swagger 文档,有独立于接口的 mock 实现。
  9. 单元测试:利用 net/http/httptest 标准包实现 API 单元测试。
  10. 依赖管理:使用 go mod 进行依赖管理。

安装使用步骤

前提条件

已下载本项目的源码文件,且需安装以下依赖工具:

启动项目

bash $ cd omgind $ air $ make start $ go run cmd/omgind/main.go web -c./configs/config.toml -m./configs/model.conf --menu./configs/menu.yaml 启动成功后,可在浏览器访问 http://127.0.0.1:10088/swagger/index.html

生成 swagger 文档

bash make swagger swag init --parseDependency --generalInfo./cmd/${APP}/main.go --output./internal/app/swagger

重新生成依赖注入文件

bash make wire wire gen./internal/app

omgind-cli 工具使用

创建项目

bash omgind-cli new -d test-omgind -p test-omgind -m

快速生成业务模块

创建模板 task.yaml: bash name: Task comment: 任务管理 fields: - name: Code type: string comment: 任务编号 required: true binding_options: "" gorm_options: "size:50;index;" - name: Name type: string comment: 任务名称 required: true binding_options: "" gorm_options: "size:50;index;" - name: Memo type: string comment: 任务备注 required: false binding_options: "" gorm_options: "size:1024;" 执行生成命令并运行: bash cd test-omgind omgind-cli g -d. -p test-omgind -f./task.yaml make swagger make wire make start

下载地址

点击下载 【提取码: 4003】【解压密码: www.makuang.net】