Skip to content

Commit 2f56037

Browse files
author
piexlmax
committed
Merge remote-tracking branch 'origin/main'
2 parents f3c9812 + cc8b09a commit 2f56037

Some content is hidden

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

49 files changed

+527
-277
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ swag init
165165

166166
> 执行上面的命令后,server目录下会出现docs文件夹里的 `docs.go`, `swagger.json`, `swagger.yaml` 三个文件更新,启动go服务之后, 在浏览器输入 [http://localhost:8888/swagger/index.html](http://localhost:8888/swagger/index.html) 即可查看swagger文档
167167
168+
### 2.4 VSCode工作区
169+
170+
#### 2.4.1 开发
171+
172+
使用`VSCode`打开根目录下的工作区文件`gin-vue-admin.code-workspace`,在边栏可以看到三个虚拟目录:`backend``frontend``root`
173+
174+
#### 2.4.2 运行/调试
175+
176+
在运行和调试中也可以看到三个task:`Backend``Frontend``Both (Backend & Frontend)`。运行`Both (Backend & Frontend)`可以同时启动前后端项目。
177+
178+
#### 2.4.3 settings
179+
180+
在工作区配置文件中有`go.toolsEnvVars`字段,是用于`VSCode`自身的go工具环境变量。此外在多go版本的系统中,可以通过`gopath``go.goroot`指定运行版本。
181+
182+
```json
183+
"go.gopath": null,
184+
"go.goroot": null,
185+
```
168186

169187
## 3. 技术选型
170188

gin-vue-admin.code-workspace

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "server",
5+
"name": "backend"
6+
},
7+
{
8+
"path": "web",
9+
"name": "frontend"
10+
},
11+
{
12+
"path": ".",
13+
"name": "root"
14+
}
15+
],
16+
"settings": {
17+
"go.toolsEnvVars": {
18+
"GOPROXY": "https://goproxy.cn,direct",
19+
"GONOPROXY": "none;"
20+
}
21+
},
22+
"launch": {
23+
"version": "0.2.0",
24+
"configurations": [
25+
{
26+
"type": "go",
27+
"request": "launch",
28+
"name": "Backend",
29+
"cwd": "${workspaceFolder:backend}",
30+
"program": "${workspaceFolder:backend}/main.go"
31+
},
32+
{
33+
"type": "node",
34+
"request": "launch",
35+
"cwd": "${workspaceFolder:frontend}",
36+
"name": "Frontend",
37+
"runtimeExecutable": "npm",
38+
"runtimeArgs": ["run-script", "serve"]
39+
}
40+
],
41+
"compounds": [
42+
{
43+
"name": "Both (Backend & Frontend)",
44+
"configurations": ["Backend", "Frontend"],
45+
"stopAll": true
46+
}
47+
]
48+
}
49+
}

server/api/v1/system/sys_dictionary.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ func (s *DictionaryApi) UpdateSysDictionary(c *gin.Context) {
8080
func (s *DictionaryApi) FindSysDictionary(c *gin.Context) {
8181
var dictionary system.SysDictionary
8282
_ = c.ShouldBindQuery(&dictionary)
83-
if sysDictionary, err := dictionaryService.GetSysDictionary(dictionary.Type, dictionary.ID); err != nil {
84-
global.GVA_LOG.Error("查询失败!", zap.Error(err))
85-
response.FailWithMessage("查询失败", c)
83+
if sysDictionary, err := dictionaryService.GetSysDictionary(dictionary.Type, dictionary.ID, dictionary.Status); err != nil {
84+
global.GVA_LOG.Error("字典未创建或未开启!", zap.Error(err))
85+
response.FailWithMessage("字典未创建或未开启", c)
8686
} else {
8787
response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
8888
}

server/config.docker.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ email:
3535
secret: 'xxx'
3636
nickname: 'test'
3737

38-
# casbin configuration
39-
casbin:
40-
model-path: './resource/rbac_model.conf'
41-
4238
# system configuration
4339
system:
4440
env: 'public' # Change to "develop" to skip authentication for development mode

server/config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ email:
3535
secret: 'xxx'
3636
nickname: 'test'
3737

38-
# casbin configuration
39-
casbin:
40-
model-path: './resource/rbac_model.conf'
41-
4238
# system configuration
4339
system:
4440
env: 'public' # Change to "develop" to skip authentication for development mode

server/config/casbin.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

server/config/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ type Server struct {
55
Zap Zap `mapstructure:"zap" json:"zap" yaml:"zap"`
66
Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"`
77
Email Email `mapstructure:"email" json:"email" yaml:"email"`
8-
Casbin Casbin `mapstructure:"casbin" json:"casbin" yaml:"casbin"`
98
System System `mapstructure:"system" json:"system" yaml:"system"`
109
Captcha Captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"`
1110
// auto

server/config/zap.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package config
22

3+
import (
4+
"go.uber.org/zap/zapcore"
5+
"strings"
6+
)
7+
38
type Zap struct {
49
Level string `mapstructure:"level" json:"level" yaml:"level"` // 级别
510
Prefix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"` // 日志前缀
@@ -12,3 +17,44 @@ type Zap struct {
1217
ShowLine bool `mapstructure:"show-line" json:"show-line" yaml:"show-line"` // 显示行
1318
LogInConsole bool `mapstructure:"log-in-console" json:"log-in-console" yaml:"log-in-console"` // 输出控制台
1419
}
20+
21+
// ZapEncodeLevel 根据 EncodeLevel 返回 zapcore.LevelEncoder
22+
// Author [SliverHorn](https://github.com/SliverHorn)
23+
func (z *Zap) ZapEncodeLevel() zapcore.LevelEncoder {
24+
switch {
25+
case z.EncodeLevel == "LowercaseLevelEncoder": // 小写编码器(默认)
26+
return zapcore.LowercaseLevelEncoder
27+
case z.EncodeLevel == "LowercaseColorLevelEncoder": // 小写编码器带颜色
28+
return zapcore.LowercaseColorLevelEncoder
29+
case z.EncodeLevel == "CapitalLevelEncoder": // 大写编码器
30+
return zapcore.CapitalLevelEncoder
31+
case z.EncodeLevel == "CapitalColorLevelEncoder": // 大写编码器带颜色
32+
return zapcore.CapitalColorLevelEncoder
33+
default:
34+
return zapcore.LowercaseLevelEncoder
35+
}
36+
}
37+
38+
// TransportLevel 根据字符串转化为 zapcore.Level
39+
// Author [SliverHorn](https://github.com/SliverHorn)
40+
func (z *Zap) TransportLevel() zapcore.Level {
41+
z.Level = strings.ToLower(z.Level)
42+
switch z.Level {
43+
case "debug":
44+
return zapcore.DebugLevel
45+
case "info":
46+
return zapcore.InfoLevel
47+
case "warn":
48+
return zapcore.WarnLevel
49+
case "error":
50+
return zapcore.WarnLevel
51+
case "dpanic":
52+
return zapcore.DPanicLevel
53+
case "panic":
54+
return zapcore.PanicLevel
55+
case "fatal":
56+
return zapcore.FatalLevel
57+
default:
58+
return zapcore.DebugLevel
59+
}
60+
}

server/core/internal/file_rotatelogs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type fileRotatelogs struct{}
1818
func (r *fileRotatelogs) GetWriteSyncer(level string) (zapcore.WriteSyncer, error) {
1919
fileWriter, err := rotatelogs.New(
2020
path.Join(global.GVA_CONFIG.Zap.Director, "%Y-%m-%d", level+".log"),
21-
rotatelogs.ForceNewFile(),
2221
rotatelogs.WithClock(rotatelogs.Local),
2322
rotatelogs.WithMaxAge(time.Duration(global.GVA_CONFIG.Zap.MaxAge)*24*time.Hour), // 日志留存时间
2423
rotatelogs.WithRotationTime(time.Hour*24),

server/core/internal/zap.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package internal
2+
3+
import (
4+
"fmt"
5+
"github.com/flipped-aurora/gin-vue-admin/server/global"
6+
"go.uber.org/zap"
7+
"go.uber.org/zap/zapcore"
8+
"time"
9+
)
10+
11+
var Zap = new(_zap)
12+
13+
type _zap struct{}
14+
15+
// GetEncoder 获取 zapcore.Encoder
16+
// Author [SliverHorn](https://github.com/SliverHorn)
17+
func (z *_zap) GetEncoder() zapcore.Encoder {
18+
if global.GVA_CONFIG.Zap.Format == "json" {
19+
return zapcore.NewJSONEncoder(z.GetEncoderConfig())
20+
}
21+
return zapcore.NewConsoleEncoder(z.GetEncoderConfig())
22+
}
23+
24+
// GetEncoderConfig 获取zapcore.EncoderConfig
25+
// Author [SliverHorn](https://github.com/SliverHorn)
26+
func (z *_zap) GetEncoderConfig() zapcore.EncoderConfig {
27+
return zapcore.EncoderConfig{
28+
MessageKey: "message",
29+
LevelKey: "level",
30+
TimeKey: "time",
31+
NameKey: "logger",
32+
CallerKey: "caller",
33+
StacktraceKey: global.GVA_CONFIG.Zap.StacktraceKey,
34+
LineEnding: zapcore.DefaultLineEnding,
35+
EncodeLevel: global.GVA_CONFIG.Zap.ZapEncodeLevel(),
36+
EncodeTime: z.CustomTimeEncoder,
37+
EncodeDuration: zapcore.SecondsDurationEncoder,
38+
EncodeCaller: zapcore.FullCallerEncoder,
39+
}
40+
}
41+
42+
// GetEncoderCore 获取Encoder的 zapcore.Core
43+
// Author [SliverHorn](https://github.com/SliverHorn)
44+
func (z *_zap) GetEncoderCore(l zapcore.Level, level zap.LevelEnablerFunc) zapcore.Core {
45+
writer, err := FileRotatelogs.GetWriteSyncer(l.String()) // 使用file-rotatelogs进行日志分割
46+
if err != nil {
47+
fmt.Printf("Get Write Syncer Failed err:%v", err.Error())
48+
return nil
49+
}
50+
51+
return zapcore.NewCore(z.GetEncoder(), writer, level)
52+
}
53+
54+
// CustomTimeEncoder 自定义日志输出时间格式
55+
// Author [SliverHorn](https://github.com/SliverHorn)
56+
func (z *_zap) CustomTimeEncoder(t time.Time, encoder zapcore.PrimitiveArrayEncoder) {
57+
encoder.AppendString(t.Format(global.GVA_CONFIG.Zap.Prefix + "2006/01/02 - 15:04:05.000"))
58+
}
59+
60+
// GetZapCores 根据配置文件的Level获取 []zapcore.Core
61+
// Author [SliverHorn](https://github.com/SliverHorn)
62+
func (z *_zap) GetZapCores() []zapcore.Core {
63+
cores := make([]zapcore.Core, 0, 7)
64+
for level := global.GVA_CONFIG.Zap.TransportLevel(); level <= zapcore.FatalLevel; level++ {
65+
cores = append(cores, z.GetEncoderCore(level, z.GetLevelPriority(level)))
66+
}
67+
return cores
68+
}
69+
70+
// GetLevelPriority 根据 zapcore.Level 获取 zap.LevelEnablerFunc
71+
// Author [SliverHorn](https://github.com/SliverHorn)
72+
func (z *_zap) GetLevelPriority(level zapcore.Level) zap.LevelEnablerFunc {
73+
switch level {
74+
case zapcore.DebugLevel:
75+
return func(level zapcore.Level) bool { // 调试级别
76+
return level == zap.DebugLevel
77+
}
78+
case zapcore.InfoLevel:
79+
return func(level zapcore.Level) bool { // 日志级别
80+
return level == zap.InfoLevel
81+
}
82+
case zapcore.WarnLevel:
83+
return func(level zapcore.Level) bool { // 警告级别
84+
return level == zap.WarnLevel
85+
}
86+
case zapcore.ErrorLevel:
87+
return func(level zapcore.Level) bool { // 错误级别
88+
return level == zap.ErrorLevel
89+
}
90+
case zapcore.DPanicLevel:
91+
return func(level zapcore.Level) bool { // dpanic级别
92+
return level == zap.DPanicLevel
93+
}
94+
case zapcore.PanicLevel:
95+
return func(level zapcore.Level) bool { // panic级别
96+
return level == zap.PanicLevel
97+
}
98+
case zapcore.FatalLevel:
99+
return func(level zapcore.Level) bool { // 终止级别
100+
return level == zap.FatalLevel
101+
}
102+
default:
103+
return func(level zapcore.Level) bool { // 调试级别
104+
return level == zap.DebugLevel
105+
}
106+
}
107+
}

server/core/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ func RunWindowsServer() {
3737

3838
fmt.Printf(`
3939
欢迎使用 gin-vue-admin
40-
当前版本:v2.5.2
40+
当前版本:v2.5.3beta
4141
加群方式:微信号:shouzi_1994 QQ群:622360840
4242
插件市场:https://plugin.gin-vue-admin.com
4343
GVA讨论社区:https://support.qq.com/products/371961
4444
默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
4545
默认前端文件运行地址:http://127.0.0.1:8080
46-
如果项目让您获得了收益,希望您能请团队喝杯可乐:https://www.github.com/flipped-aurora/gin-vue-admin/server.com/docs/coffee
46+
如果项目让您获得了收益,希望您能请团队喝杯可乐:https://www.gin-vue-admin.com/docs/coffee
4747
`, address)
4848
global.GVA_LOG.Error(s.ListenAndServe().Error())
4949
}

0 commit comments

Comments
 (0)