Skip to content

Commit

Permalink
Merge pull request #110 from LyricTian/develop
Browse files Browse the repository at this point in the history
Refactoring to v8.0
  • Loading branch information
LyricTian authored Aug 2, 2021
2 parents b07b9e7 + 301ad48 commit a904050
Show file tree
Hide file tree
Showing 113 changed files with 3,223 additions and 4,257 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

NOW = $(shell date -u '+%Y%m%d%I%M%S')

RELEASE_VERSION = v7.0.0
RELEASE_VERSION = v8.0.0

APP = gin-admin
SERVER_BIN = ./cmd/${APP}/${APP}
Expand Down
50 changes: 47 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- 遵循 `RESTful API` 设计规范 & 基于接口的编程规范
- 基于 `GIN` 框架,提供了丰富的中间件支持(JWTAuth、CORS、RequestLogger、RequestRateLimiter、TraceID、CasbinEnforce、Recover、GZIP)
- 基于 `Casbin` 的 RBAC 访问控制模型 -- **权限控制可以细粒度到按钮 & 接口**
- 基于 `Gorm` 的数据库存储
- 基于 `Gorm 2.0` 的数据库访问层 - 全功能 ORM
- 基于 `WIRE` 的依赖注入 -- 依赖注入本身的作用是解决了各个模块间层级依赖繁琐的初始化过程
- 基于 `Logrus & Context` 实现了日志输出,通过结合 Context 实现了统一的 TraceID/UserID 等关键字段的输出(同时支持日志钩子写入到`Gorm`)
- 基于 `JWT` 的用户认证 -- 基于 JWT 的黑名单验证机制
Expand All @@ -36,7 +36,7 @@ go get -u github.com/swaggo/swag/cmd/swag
## 依赖框架

- [Gin](https://gin-gonic.com/) -- The fastest full-featured web framework for Go.
- [GORM](http://gorm.io/) -- The fantastic ORM library for Golang
- [GORM](https://gorm.io/) -- The fantastic ORM library for Golang
- [Casbin](https://casbin.org/) -- An authorization library that supports access control models like ACL, RBAC, ABAC in Golang
- [Wire](https://github.com/google/wire) -- Compile-time Dependency Injection for Go

Expand Down Expand Up @@ -145,6 +145,50 @@ make start
export CGO_ENABLED=1; export CC=gcc; go get -v -x github.com/mattn/go-sqlite3
```

## 目录结构

```
├── cmd
│ └── gin-admin
│ └── main.go # 入口文件
├── configs
│ ├── config.toml # 配置文件
│ ├── menu.yaml # 菜单初始化配置
│ └── model.conf # casbin 策略配置
├── docs # 文档
├── internal
│ └── app
│ ├── api # API 处理层
│ ├── config # 配置文件映射
│ ├── contextx # 统一上下文处理
│ ├── dao # 数据访问层
│ ├── ginx # gin 扩展模块
│ ├── middleware # gin 中间件模块
│ ├── module # 通用业务处理模块
│ ├── router # 路由层
│ ├── schema # 统一入参、出参对象映射
│ ├── service # 业务逻辑层
│ ├── swagger # swagger 生成文件
│ ├── test # 模块单元测试
├── pkg
│ ├── auth
│ │ └── jwtauth # jwt 认证模块
│ ├── errors # 错误处理模块
│ ├── gormx # gorm 扩展模块
│ ├── logger # 日志模块
│ │ ├── hook
│ └── util # 工具包
│ ├── conv
│ ├── hash
│ ├── json
│ ├── snowflake
│ ├── structure
│ ├── trace
│ ├── uuid
│ └── yaml
└── scripts # 统一处理脚本
```

## 互动交流

<div>
Expand All @@ -158,7 +202,7 @@ export CGO_ENABLED=1; export CC=gcc; go get -v -x github.com/mattn/go-sqlite3

[reportcard-url]: https://goreportcard.com/report/github.com/LyricTian/gin-admin
[reportcard-image]: https://goreportcard.com/badge/github.com/LyricTian/gin-admin
[godoc-url]: https://pkg.go.dev/github.com/LyricTian/gin-admin/v7
[godoc-url]: https://pkg.go.dev/github.com/LyricTian/gin-admin/v8
[godoc-image]: https://godoc.org/github.com/LyricTian/gin-admin?status.svg
[license-url]: http://opensource.org/licenses/MIT
[license-image]: https://img.shields.io/npm/l/express.svg
20 changes: 10 additions & 10 deletions cmd/gin-admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import (
"context"
"os"

"github.com/LyricTian/gin-admin/v7/internal/app"
"github.com/LyricTian/gin-admin/v7/pkg/logger"
"github.com/urfave/cli/v2"

"github.com/LyricTian/gin-admin/v8/internal/app"
"github.com/LyricTian/gin-admin/v8/pkg/logger"
)

// VERSION 版本号,可以通过编译的方式指定版本号:go build -ldflags "-X main.VERSION=x.x.x"
var VERSION = "7.0.0"
var VERSION = "8.0.0"

// @title gin-admin
// @version 7.0.0
// @version 8.0.0
// @description RBAC scaffolding based on GIN + GORM + CASBIN + WIRE.
// @securityDefinitions.apikey ApiKeyAuth
// @in header
Expand All @@ -32,7 +33,6 @@ var VERSION = "7.0.0"
// @contact.name LyricTian
// @contact.email [email protected]
func main() {
logger.SetVersion(VERSION)
ctx := logger.NewTagContext(context.Background(), "__main__")

app := cli.NewApp()
Expand All @@ -51,27 +51,27 @@ func main() {
func newWebCmd(ctx context.Context) *cli.Command {
return &cli.Command{
Name: "web",
Usage: "运行web服务",
Usage: "Run http server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "conf",
Aliases: []string{"c"},
Usage: "配置文件(.json,.yaml,.toml)",
Usage: "App configuration file(.json,.yaml,.toml)",
Required: true,
},
&cli.StringFlag{
Name: "model",
Aliases: []string{"m"},
Usage: "casbin的访问控制模型(.conf)",
Usage: "Casbin model configuration(.conf)",
Required: true,
},
&cli.StringFlag{
Name: "menu",
Usage: "初始化菜单数据配置文件(.yaml)",
Usage: "Initialize menu's data configuration(.yaml)",
},
&cli.StringFlag{
Name: "www",
Usage: "静态站点目录",
Usage: "Static site directory",
},
},
Action: func(c *cli.Context) error {
Expand Down
34 changes: 15 additions & 19 deletions configs/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ KeyFile = ""
ShutdownTimeout = 30
# 允许的最大内容长度(64M)
MaxContentLength = 67108864
# 允许输出的最大日志长度
MaxLoggerLength = 4096
# 允许输出的最大请求日志长度
MaxReqLoggerLength = 1024

[Menu]
# 使用启用初始化菜单数据
Enable = true
# 数据文件(yaml,也可以启动服务时使用-menu指定)
# 数据文件(yaml,也可以启动服务时使用 -menu 指定)
Data = ""

[Casbin]
Expand All @@ -56,7 +56,7 @@ OutputFile = "data/gin-admin.log"
# 是否启用日志钩子
EnableHook = false
# 写入钩子的日志级别
HookLevels = ["info","warn","error"]
HookLevels = ["info", "warn", "error"]
# 日志钩子(支持:gorm/mongo)
Hook = "gorm"
# 写入钩子的最大工作线程数量
Expand All @@ -73,12 +73,6 @@ MaxLifetime = 7200
MaxOpenConns = 1
# 设置空闲连接池中的最大连接数
MaxIdleConns = 1
# 数据库表名
Table = "g_logger"

[LogMongoHook]
# 数据库表名
Collection = "g_logger"

# 服务监控(GOPS:https://github.com/google/gops)
[Monitor]
Expand All @@ -90,12 +84,14 @@ Addr = "127.0.0.1:16060"
ConfigDir = ""

[Root]
# 用户ID
UserID = 9
# 登录用户名
UserName = "root"
# 登录密码
Password = "abc-123"
# 显示的真实姓名
RealName = "超级管理员"
# 显示名称
RealName = "Admin"

# redis配置信息
[Redis]
Expand All @@ -117,9 +113,9 @@ Expired = 7200
Store = "file"
# 文件路径
FilePath = "data/jwt_auth.db"
# redis数据库(如果存储方式是redis,则指定存储的数据库)
# redis 数据库(如果存储方式是redis,则指定存储的数据库)
RedisDB = 10
# 存储到redis数据库中的键名前缀
# 存储到 redis 数据库中的键名前缀
RedisPrefix = "auth_"

[Captcha]
Expand All @@ -136,7 +132,7 @@ RedisDB = 10
# 存储到redis数据库中的键名前缀
RedisPrefix = "captcha_"

# 请求频率限制(如果redis可用则使用redis,否则使用内存存储)
# 请求频率限制
[RateLimiter]
# 是否启用
Enable = false
Expand All @@ -151,7 +147,7 @@ Enable = false
# 允许跨域请求的域名列表(*表示全部允许)
AllowOrigins = ["*"]
# 允许跨域请求的请求方式列表
AllowMethods = ["GET","POST","PUT","DELETE","PATCH"]
AllowMethods = ["GET", "POST", "PUT", "DELETE", "PATCH"]
# 允许客户端与跨域请求一起使用的非简单标头的列表
AllowHeaders = []
# 请求是否可以包含cookie,HTTP身份验证或客户端SSL证书等用户凭据
Expand All @@ -163,7 +159,7 @@ MaxAge = 7200
# 是否启用
Enable = false
# 排除的文件扩展名
ExcludedExtentions = [".png",".gif",".jpeg",".jpg"]
ExcludedExtentions = [".png", ".gif", ".jpeg", ".jpg"]
# 排除的请求路径
ExcludedPaths = []

Expand All @@ -187,7 +183,7 @@ EnableAutoMigrate = true
# 连接地址
Host = "127.0.0.1"
# 连接端口
Port= 3306
Port = 3306
# 用户名
User = "root"
# 密码
Expand All @@ -201,7 +197,7 @@ Parameters = "charset=utf8mb4&parseTime=True&loc=Local&allowNativePasswords=true
# 连接地址
Host = "127.0.0.1"
# 连接端口
Port= 5432
Port = 5432
# 用户名
User = "root"
# 密码
Expand Down
37 changes: 0 additions & 37 deletions configs/menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,6 @@
icon: dashboard
router: "/dashboard"
sequence: 9
- name: DEMO
icon: tag
router: "/example/demo"
sequence: 8
actions:
- code: add
name: 新增
resources:
- method: POST
path: "/api/v1/demos"
- code: edit
name: 编辑
resources:
- method: GET
path: "/api/v1/demos/:id"
- method: PUT
path: "/api/v1/demos/:id"
- code: del
name: 删除
resources:
- method: DELETE
path: "/api/v1/demos/:id"
- code: query
name: 查询
resources:
- method: GET
path: "/api/v1/demos"
- code: disable
name: 禁用
resources:
- method: PATCH
path: "/api/v1/demos/:id/disable"
- code: enable
name: 启用
resources:
- method: PATCH
path: "/api/v1/demos/:id/enable"
- name: 系统管理
icon: setting
sequence: 7
Expand Down
2 changes: 1 addition & 1 deletion configs/model.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ e = some(where (p.eft == allow))
m = g(r.sub, p.sub) == true \
&& keyMatch2(r.obj, p.obj) == true \
&& regexMatch(r.act, p.act) == true \
|| r.sub == "root"
|| r.sub == "9"
Loading

0 comments on commit a904050

Please sign in to comment.