Skip to content

Commit a904050

Browse files
authored
Merge pull request #110 from LyricTian/develop
Refactoring to v8.0
2 parents b07b9e7 + 301ad48 commit a904050

File tree

113 files changed

+3223
-4257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+3223
-4257
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
RELEASE_VERSION = v7.0.0
5+
RELEASE_VERSION = v8.0.0
66

77
APP = gin-admin
88
SERVER_BIN = ./cmd/${APP}/${APP}

README.md

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

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

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

148+
## 目录结构
149+
150+
```
151+
├── cmd
152+
│ └── gin-admin
153+
│ └── main.go # 入口文件
154+
├── configs
155+
│ ├── config.toml # 配置文件
156+
│ ├── menu.yaml # 菜单初始化配置
157+
│ └── model.conf # casbin 策略配置
158+
├── docs # 文档
159+
├── internal
160+
│ └── app
161+
│ ├── api # API 处理层
162+
│ ├── config # 配置文件映射
163+
│ ├── contextx # 统一上下文处理
164+
│ ├── dao # 数据访问层
165+
│ ├── ginx # gin 扩展模块
166+
│ ├── middleware # gin 中间件模块
167+
│ ├── module # 通用业务处理模块
168+
│ ├── router # 路由层
169+
│ ├── schema # 统一入参、出参对象映射
170+
│ ├── service # 业务逻辑层
171+
│ ├── swagger # swagger 生成文件
172+
│ ├── test # 模块单元测试
173+
├── pkg
174+
│ ├── auth
175+
│ │ └── jwtauth # jwt 认证模块
176+
│ ├── errors # 错误处理模块
177+
│ ├── gormx # gorm 扩展模块
178+
│ ├── logger # 日志模块
179+
│ │ ├── hook
180+
│ └── util # 工具包
181+
│ ├── conv
182+
│ ├── hash
183+
│ ├── json
184+
│ ├── snowflake
185+
│ ├── structure
186+
│ ├── trace
187+
│ ├── uuid
188+
│ └── yaml
189+
└── scripts # 统一处理脚本
190+
```
191+
148192
## 互动交流
149193

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

159203
[reportcard-url]: https://goreportcard.com/report/github.com/LyricTian/gin-admin
160204
[reportcard-image]: https://goreportcard.com/badge/github.com/LyricTian/gin-admin
161-
[godoc-url]: https://pkg.go.dev/github.com/LyricTian/gin-admin/v7
205+
[godoc-url]: https://pkg.go.dev/github.com/LyricTian/gin-admin/v8
162206
[godoc-image]: https://godoc.org/github.com/LyricTian/gin-admin?status.svg
163207
[license-url]: http://opensource.org/licenses/MIT
164208
[license-image]: https://img.shields.io/npm/l/express.svg

cmd/gin-admin/main.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ import (
1313
"context"
1414
"os"
1515

16-
"github.com/LyricTian/gin-admin/v7/internal/app"
17-
"github.com/LyricTian/gin-admin/v7/pkg/logger"
1816
"github.com/urfave/cli/v2"
17+
18+
"github.com/LyricTian/gin-admin/v8/internal/app"
19+
"github.com/LyricTian/gin-admin/v8/pkg/logger"
1920
)
2021

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

2425
// @title gin-admin
25-
// @version 7.0.0
26+
// @version 8.0.0
2627
// @description RBAC scaffolding based on GIN + GORM + CASBIN + WIRE.
2728
// @securityDefinitions.apikey ApiKeyAuth
2829
// @in header
@@ -32,7 +33,6 @@ var VERSION = "7.0.0"
3233
// @contact.name LyricTian
3334
// @contact.email [email protected]
3435
func main() {
35-
logger.SetVersion(VERSION)
3636
ctx := logger.NewTagContext(context.Background(), "__main__")
3737

3838
app := cli.NewApp()
@@ -51,27 +51,27 @@ func main() {
5151
func newWebCmd(ctx context.Context) *cli.Command {
5252
return &cli.Command{
5353
Name: "web",
54-
Usage: "运行web服务",
54+
Usage: "Run http server",
5555
Flags: []cli.Flag{
5656
&cli.StringFlag{
5757
Name: "conf",
5858
Aliases: []string{"c"},
59-
Usage: "配置文件(.json,.yaml,.toml)",
59+
Usage: "App configuration file(.json,.yaml,.toml)",
6060
Required: true,
6161
},
6262
&cli.StringFlag{
6363
Name: "model",
6464
Aliases: []string{"m"},
65-
Usage: "casbin的访问控制模型(.conf)",
65+
Usage: "Casbin model configuration(.conf)",
6666
Required: true,
6767
},
6868
&cli.StringFlag{
6969
Name: "menu",
70-
Usage: "初始化菜单数据配置文件(.yaml)",
70+
Usage: "Initialize menu's data configuration(.yaml)",
7171
},
7272
&cli.StringFlag{
7373
Name: "www",
74-
Usage: "静态站点目录",
74+
Usage: "Static site directory",
7575
},
7676
},
7777
Action: func(c *cli.Context) error {

configs/config.toml

+15-19
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ KeyFile = ""
2323
ShutdownTimeout = 30
2424
# 允许的最大内容长度(64M)
2525
MaxContentLength = 67108864
26-
# 允许输出的最大日志长度
27-
MaxLoggerLength = 4096
26+
# 允许输出的最大请求日志长度
27+
MaxReqLoggerLength = 1024
2828

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

3535
[Casbin]
@@ -56,7 +56,7 @@ OutputFile = "data/gin-admin.log"
5656
# 是否启用日志钩子
5757
EnableHook = false
5858
# 写入钩子的日志级别
59-
HookLevels = ["info","warn","error"]
59+
HookLevels = ["info", "warn", "error"]
6060
# 日志钩子(支持:gorm/mongo)
6161
Hook = "gorm"
6262
# 写入钩子的最大工作线程数量
@@ -73,12 +73,6 @@ MaxLifetime = 7200
7373
MaxOpenConns = 1
7474
# 设置空闲连接池中的最大连接数
7575
MaxIdleConns = 1
76-
# 数据库表名
77-
Table = "g_logger"
78-
79-
[LogMongoHook]
80-
# 数据库表名
81-
Collection = "g_logger"
8276

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

9286
[Root]
87+
# 用户ID
88+
UserID = 9
9389
# 登录用户名
9490
UserName = "root"
9591
# 登录密码
9692
Password = "abc-123"
97-
# 显示的真实姓名
98-
RealName = "超级管理员"
93+
# 显示名称
94+
RealName = "Admin"
9995

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

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

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

@@ -187,7 +183,7 @@ EnableAutoMigrate = true
187183
# 连接地址
188184
Host = "127.0.0.1"
189185
# 连接端口
190-
Port= 3306
186+
Port = 3306
191187
# 用户名
192188
User = "root"
193189
# 密码
@@ -201,7 +197,7 @@ Parameters = "charset=utf8mb4&parseTime=True&loc=Local&allowNativePasswords=true
201197
# 连接地址
202198
Host = "127.0.0.1"
203199
# 连接端口
204-
Port= 5432
200+
Port = 5432
205201
# 用户名
206202
User = "root"
207203
# 密码

configs/menu.yaml

-37
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,6 @@
44
icon: dashboard
55
router: "/dashboard"
66
sequence: 9
7-
- name: DEMO
8-
icon: tag
9-
router: "/example/demo"
10-
sequence: 8
11-
actions:
12-
- code: add
13-
name: 新增
14-
resources:
15-
- method: POST
16-
path: "/api/v1/demos"
17-
- code: edit
18-
name: 编辑
19-
resources:
20-
- method: GET
21-
path: "/api/v1/demos/:id"
22-
- method: PUT
23-
path: "/api/v1/demos/:id"
24-
- code: del
25-
name: 删除
26-
resources:
27-
- method: DELETE
28-
path: "/api/v1/demos/:id"
29-
- code: query
30-
name: 查询
31-
resources:
32-
- method: GET
33-
path: "/api/v1/demos"
34-
- code: disable
35-
name: 禁用
36-
resources:
37-
- method: PATCH
38-
path: "/api/v1/demos/:id/disable"
39-
- code: enable
40-
name: 启用
41-
resources:
42-
- method: PATCH
43-
path: "/api/v1/demos/:id/enable"
447
- name: 系统管理
458
icon: setting
469
sequence: 7

configs/model.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ e = some(where (p.eft == allow))
1414
m = g(r.sub, p.sub) == true \
1515
&& keyMatch2(r.obj, p.obj) == true \
1616
&& regexMatch(r.act, p.act) == true \
17-
|| r.sub == "root"
17+
|| r.sub == "9"

0 commit comments

Comments
 (0)