Git Product home page Git Product logo

gin-admin's Introduction

Gin Admin

基于 Gin + GORM + Casbin + Dig 实现的RBAC权限管理脚手架,目的是提供一套轻量的中后台开发框架,方便、快速的完成业务需求的开发。

ReportCard GoDoc License

  • 在线演示地址 (用户名:root,密码:abc-123)(温馨提醒:为了达到更好的演示效果,这里给出了拥有最高权限的用户,请手下留情,只操作自己新增的数据,不要动平台本身的数据!谢谢!
  • Swagger 文档地址

特性

  • 遵循 RESTful API 设计规范
  • 基于 Casbin 的 RBAC 访问控制模型
  • 存储分离(存储层对外采用接口的方式供业务层调用,实现了存储层的完全隔离)
  • 依赖注入(基于dig)
  • 日志追踪(基于logrus,日志钩子支持 gorm)
  • JWT 认证(基于黑名单的认证模式,存储支持:file/redis)
  • 支持 Swagger 文档
  • 单元测试

下载并运行

获取代码

go get -v github.com/LyricTian/gin-admin/cmd/server

运行

root 用户的用户名及密码在配置文件(configs/config.toml)中,默认为:root/abc-123

运行服务

也可以使用脚本运行(详情可查看Makefile):make start

cd github.com/LyricTian/gin-admin/cmd/server
go build -o server
./server -c ../../configs/config.toml -m ../../configs/model.conf -swagger ../../internal/app/swagger

启动成功之后,可在浏览器中输入地址访问:http://127.0.0.1:10088/swagger/

温馨提醒

  1. 默认配置采用的是 sqlite 数据库,数据库文件(自动生成)在data/gadmin.db。如果想切换为mysqlpostgres,请更改配置文件,并创建数据库(数据库创建脚本在script目录下)。
  2. 日志的默认配置为标准输出,如果想切换到写入文件或写入到 gorm 存储,可以自行切换配置。

前端实现

Swagger 文档的使用

文档规则请参考:https://github.com/teambition/swaggo/wiki/Declarative-Comments-Format

安装工具并生成文档

go get -u -v github.com/teambition/swaggo
swaggo -s ./internal/app/routers/api/swagger.go -p . -o ./internal/app/swagger

生成文档之后,可在浏览器中输入地址访问:http://127.0.0.1:10088/swagger/

项目结构概览

.
├── cmd
│   └── server:主服务
├── configs:配置文件目录
├── docs:文档目录
├── internal:内部应用
│   └── app:主应用目录
│       ├── bll:业务逻辑层接口
│       │   └── impl:业务逻辑层的接口实现
│       ├── config:配置参数(与配置文件一一映射)
│       ├── context:统一上下文
│       ├── errors:统一的错误定义
│       ├── ginplus:gin的扩展函数库
│       ├── middleware:gin中间件
│       ├── model:存储层接口
│       │   └── impl:存储层接口实现
│       ├── routers:路由层
│       │   └── api:/api路由模块
│       │       └── ctl:/api路由模块对应的控制器层
│       ├── schema:对象模型
│       ├── swagger:swagger静态目录
│       └── test:单元测试
├── pkg:公共模块
│   ├── auth:认证模块
│   │   └── jwtauth:JWT认证模块实现
│   ├── gormplus:gorm扩展实现
│   ├── logger:日志模块
│   └── util:工具库
└── scripts:执行脚本

感谢以下框架的开源支持

MIT License

Copyright (c) 2019 Lyric

与作者对话

该项目是利用业余时间进行开发的,开发思路主要是来源于自己的项目积累及个人思考,如果您有更好的想法和建议请与我进行沟通,我非常期待!下面是我的微信二维码:

gin-admin's People

Contributors

ezewu avatar lyrictian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.