Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
4ca3c2e2
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
大约 1 年 前同步成功
通知
342
Star
18155
Fork
5506
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4ca3c2e2
编写于
6月 28, 2020
作者:
G
Granty1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add base operation record code
上级
d70599f6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
84 addition
and
23 deletion
+84
-23
server/config.yaml
server/config.yaml
+10
-3
server/config/config.go
server/config/config.go
+14
-9
server/core/log.go
server/core/log.go
+6
-11
server/initialize/router.go
server/initialize/router.go
+2
-0
server/middleware/operation.go
server/middleware/operation.go
+52
-0
未找到文件。
server/config.yaml
浏览文件 @
4ca3c2e2
...
...
@@ -11,8 +11,8 @@ jwt:
# mysql connect configuration
mysql
:
username
:
root
password
:
'
Aa@6447985
'
path
:
'
127.0.0.1
:3306'
password
:
'
xxxxx
'
path
:
'
xxxxxx
:3306'
db-name
:
'
qmPlus'
config
:
'
charset=utf8&parseTime=True&loc=Local'
max-idle-conns
:
10
...
...
@@ -31,6 +31,7 @@ qiniu:
secret-key
:
'
pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY'
bucket
:
'
qm-plus-img'
img-path
:
'
http://qmplusimg.henrongyi.top'
# redis configuration
redis
:
addr
:
'
127.0.0.1:6379'
...
...
@@ -55,4 +56,10 @@ log:
prefix
:
'
[GIN-VUE-ADMIN]'
log-file
:
true
stdout
:
'
DEBUG'
file
:
'
DEBUG'
\ No newline at end of file
file
:
'
DEBUG'
# operation configuration
operation
:
skip_paths
:
-
'
/base/login'
-
'
/base/register'
\ No newline at end of file
server/config/config.go
浏览文件 @
4ca3c2e2
package
config
type
Server
struct
{
Mysql
Mysql
`mapstructure:"mysql" json:"mysql" yaml:"mysql"`
Sqlite
Sqlite
`mapstructure:"sqlite" json:"sqlite" yaml:"sqlite"`
Qiniu
Qiniu
`mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
Casbin
Casbin
`mapstructure:"casbin" json:"casbin" yaml:"casbin"`
Redis
Redis
`mapstructure:"redis" json:"redis" yaml:"redis"`
System
System
`mapstructure:"system" json:"system" yaml:"system"`
JWT
JWT
`mapstructure:"jwt" json:"jwt" yaml:"jwt"`
Captcha
Captcha
`mapstructure:"captcha" json:"captcha" yaml:"captcha"`
Log
Log
`mapstructure:"log" json:"log" yaml:"log"`
Mysql
Mysql
`mapstructure:"mysql" json:"mysql" yaml:"mysql"`
Sqlite
Sqlite
`mapstructure:"sqlite" json:"sqlite" yaml:"sqlite"`
Qiniu
Qiniu
`mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
Casbin
Casbin
`mapstructure:"casbin" json:"casbin" yaml:"casbin"`
Redis
Redis
`mapstructure:"redis" json:"redis" yaml:"redis"`
System
System
`mapstructure:"system" json:"system" yaml:"system"`
JWT
JWT
`mapstructure:"jwt" json:"jwt" yaml:"jwt"`
Captcha
Captcha
`mapstructure:"captcha" json:"captcha" yaml:"captcha"`
Log
Log
`mapstructure:"log" json:"log" yaml:"log"`
Operation
Operation
`mapstructure:"operation" json:"operation" yaml:"operation"`
}
type
System
struct
{
...
...
@@ -70,3 +71,7 @@ type Sqlite struct {
Config
string
`mapstructure:"config" json:"config" yaml:"config"`
LogMode
bool
`mapstructure:"log-mode" json:"logMode" yaml:"log-mode"`
}
type
Operation
struct
{
SkipPaths
[]
string
`mapstructure: "skip_paths" json:"skip_paths" yaml: "username"`
}
server/core/log.go
浏览文件 @
4ca3c2e2
...
...
@@ -30,26 +30,24 @@ func init() {
}
logger
:=
oplogging
.
MustGetLogger
(
module
)
var
backends
[]
oplogging
.
Backend
backends
=
registerStdout
(
c
,
backends
)
backends
=
registerFile
(
c
,
backends
)
registerStdout
(
c
,
&
backends
)
registerFile
(
c
,
&
backends
)
oplogging
.
SetBackend
(
backends
...
)
global
.
GVA_LOG
=
logger
}
func
registerStdout
(
c
config
.
Log
,
backends
[]
oplogging
.
Backend
)
[]
oplogging
.
Backend
{
func
registerStdout
(
c
config
.
Log
,
backends
*
[]
oplogging
.
Backend
)
{
if
c
.
Stdout
!=
""
{
level
,
err
:=
oplogging
.
LogLevel
(
c
.
Stdout
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
backends
=
append
(
backends
,
createBackend
(
os
.
Stdout
,
c
,
level
))
*
backends
=
append
(
*
backends
,
createBackend
(
os
.
Stdout
,
c
,
level
))
}
return
backends
}
func
registerFile
(
c
config
.
Log
,
backends
[]
oplogging
.
Backend
)
[]
oplogging
.
Backend
{
func
registerFile
(
c
config
.
Log
,
backends
*
[]
oplogging
.
Backend
)
{
if
c
.
File
!=
""
{
if
ok
,
_
:=
utils
.
PathExists
(
logDir
);
!
ok
{
// directory not exist
...
...
@@ -67,16 +65,13 @@ func registerFile(c config.Log, backends []oplogging.Backend) []oplogging.Backen
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
backends
}
level
,
err
:=
oplogging
.
LogLevel
(
c
.
File
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
backends
=
append
(
backends
,
createBackend
(
fileWriter
,
c
,
level
))
*
backends
=
append
(
*
backends
,
createBackend
(
fileWriter
,
c
,
level
))
}
return
backends
}
func
createBackend
(
w
io
.
Writer
,
c
config
.
Log
,
level
oplogging
.
Level
)
oplogging
.
Backend
{
...
...
server/initialize/router.go
浏览文件 @
4ca3c2e2
...
...
@@ -14,6 +14,8 @@ import (
func
Routers
()
*
gin
.
Engine
{
var
Router
=
gin
.
Default
()
// 操作记录
Router
.
Use
(
middleware
.
RecordRequestBody
(),
middleware
.
OperationRecord
())
// Router.Use(middleware.LoadTls()) // 打开就能玩https了
global
.
GVA_LOG
.
Debug
(
"use middleware logger"
)
// 跨域
...
...
server/middleware/operation.go
0 → 100644
浏览文件 @
4ca3c2e2
package
middleware
import
(
"bytes"
"fmt"
"gin-vue-admin/global"
"github.com/gin-gonic/gin"
"io/ioutil"
"net/http"
"time"
)
var
body
[]
byte
func
RecordRequestBody
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
if
c
.
Request
.
Method
!=
http
.
MethodGet
{
var
err
error
body
,
err
=
ioutil
.
ReadAll
(
c
.
Request
.
Body
)
if
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
err
)
}
c
.
Request
.
Body
=
ioutil
.
NopCloser
(
bytes
.
NewBuffer
(
body
))
}
else
{
body
=
nil
}
}
}
func
OperationRecord
()
gin
.
HandlerFunc
{
return
gin
.
LoggerWithConfig
(
gin
.
LoggerConfig
{
Formatter
:
func
(
param
gin
.
LogFormatterParams
)
string
{
return
fmt
.
Sprintf
(
"%s - [%s]
\"
%s %s %s %d %s
\"
%s
\"
\"
%s
\"
%s
\"\n
"
,
param
.
ClientIP
,
param
.
TimeStamp
.
Format
(
time
.
RFC1123
),
param
.
Method
,
param
.
Path
,
param
.
Request
.
Proto
,
param
.
StatusCode
,
param
.
Latency
,
param
.
Request
.
UserAgent
(),
string
(
body
),
param
.
ErrorMessage
,
)
},
// 暂时没考虑好
Output
:
nil
,
SkipPaths
:
global
.
GVA_CONFIG
.
Operation
.
SkipPaths
,
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录