Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
3c16f8a3
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
大约 1 年 前同步成功
通知
345
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看板
提交
3c16f8a3
编写于
9月 04, 2019
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
混入日志包
上级
8eae7f18
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
54 addition
and
39 deletion
+54
-39
QMPlusServer/init/initRouter/initRouter.go
QMPlusServer/init/initRouter/initRouter.go
+1
-0
QMPlusServer/init/qmlog/qmlog.go
QMPlusServer/init/qmlog/qmlog.go
+36
-0
QMPlusServer/init/qmsql/initMysql.go
QMPlusServer/init/qmsql/initMysql.go
+2
-1
QMPlusServer/init/registTable/registTable.go
QMPlusServer/init/registTable/registTable.go
+1
-0
QMPlusServer/main.go
QMPlusServer/main.go
+6
-4
QMPlusServer/middleware/logger.go
QMPlusServer/middleware/logger.go
+2
-28
QMPlusServer/model/dbModel/user.go
QMPlusServer/model/dbModel/user.go
+6
-6
未找到文件。
QMPlusServer/init/initRouter/initRouter.go
浏览文件 @
3c16f8a3
...
...
@@ -8,6 +8,7 @@ import (
"main/router"
)
//初始化总路由
func
InitRouter
()
*
gin
.
Engine
{
var
Router
=
gin
.
Default
()
Router
.
GET
(
"/swagger/*any"
,
ginSwagger
.
WrapHandler
(
swaggerFiles
.
Handler
))
...
...
QMPlusServer/init/qmlog/qmlog.go
0 → 100644
浏览文件 @
3c16f8a3
package
qmlog
// 日志初始化包 调用qmlog.QMLog.Info 记录日志 24小时切割 日志保存7天 可自行设置
import
(
"fmt"
rotatelogs
"github.com/lestrrat/go-file-rotatelogs"
"github.com/rifflock/lfshook"
"github.com/sirupsen/logrus"
"os"
"time"
)
var
QMLog
=
logrus
.
New
()
//禁止logrus的输出
func
InitLog
()
{
src
,
err
:=
os
.
OpenFile
(
os
.
DevNull
,
os
.
O_APPEND
|
os
.
O_WRONLY
,
os
.
ModeAppend
)
if
err
!=
nil
{
fmt
.
Println
(
"err"
,
err
)
}
QMLog
.
Out
=
src
QMLog
.
SetLevel
(
logrus
.
DebugLevel
)
apiLogPath
:=
"api.log"
logWriter
,
err
:=
rotatelogs
.
New
(
apiLogPath
+
".%Y-%m-%d-%H-%M.log"
,
rotatelogs
.
WithLinkName
(
apiLogPath
),
// 生成软链,指向最新日志文件
rotatelogs
.
WithMaxAge
(
7
*
24
*
time
.
Hour
),
// 文件最大保存时间
rotatelogs
.
WithRotationTime
(
24
*
time
.
Hour
),
// 日志切割时间间隔
)
writeMap
:=
lfshook
.
WriterMap
{
logrus
.
InfoLevel
:
logWriter
,
logrus
.
FatalLevel
:
logWriter
,
}
lfHook
:=
lfshook
.
NewHook
(
writeMap
,
&
logrus
.
JSONFormatter
{})
QMLog
.
AddHook
(
lfHook
)
}
QMPlusServer/init/
my
sql/initMysql.go
→
QMPlusServer/init/
qm
sql/initMysql.go
浏览文件 @
3c16f8a3
package
my
sql
package
qm
sql
import
(
"github.com/jinzhu/gorm"
...
...
@@ -9,6 +9,7 @@ import (
var
DEFAULTDB
*
gorm
.
DB
//初始化数据库并产生数据库全局变量
func
InitMysql
(
admin
config
.
Admin
)
*
gorm
.
DB
{
if
db
,
err
:=
gorm
.
Open
(
"mysql"
,
admin
.
UserName
+
":"
+
admin
.
Password
+
"@("
+
admin
.
Path
+
")/"
+
admin
.
Dbname
+
"?"
+
admin
.
Config
);
err
!=
nil
{
log
.
Printf
(
"DEFAULTDB数据库启动异常%S"
,
err
)
...
...
QMPlusServer/init/registTable/registTable.go
浏览文件 @
3c16f8a3
...
...
@@ -5,6 +5,7 @@ import (
"main/model/dbModel"
)
//注册数据库表专用
func
RegistTable
(
db
*
gorm
.
DB
)
{
db
.
AutoMigrate
(
dbModel
.
User
{})
}
QMPlusServer/main.go
浏览文件 @
3c16f8a3
...
...
@@ -3,17 +3,19 @@ package main
import
(
"main/config"
"main/init/initRouter"
"main/init/mysql"
"main/init/qmlog"
"main/init/qmsql"
"main/init/registTable"
"net/http"
"time"
)
func
main
()
{
registTable
.
RegistTable
(
my
sql
.
InitMysql
(
config
.
Dbconfig
.
Admin
))
defer
my
sql
.
DEFAULTDB
.
Close
()
qmlog
.
InitLog
()
registTable
.
RegistTable
(
qm
sql
.
InitMysql
(
config
.
Dbconfig
.
Admin
))
defer
qm
sql
.
DEFAULTDB
.
Close
()
Router
:=
initRouter
.
InitRouter
()
//qmlog.QMLog.Info("服务器开启") // 日志测试代码
s
:=
&
http
.
Server
{
Addr
:
":8888"
,
Handler
:
Router
,
...
...
QMPlusServer/middleware/logger.go
浏览文件 @
3c16f8a3
package
middleware
import
(
"fmt"
"github.com/gin-gonic/gin"
"github.com/lestrrat/go-file-rotatelogs"
"github.com/rifflock/lfshook"
"github.com/sirupsen/logrus"
"os"
"main/init/qmlog"
"time"
)
func
Logger
()
gin
.
HandlerFunc
{
logClient
:=
logrus
.
New
()
//禁止logrus的输出
src
,
err
:=
os
.
OpenFile
(
os
.
DevNull
,
os
.
O_APPEND
|
os
.
O_WRONLY
,
os
.
ModeAppend
)
if
err
!=
nil
{
fmt
.
Println
(
"err"
,
err
)
}
logClient
.
Out
=
src
logClient
.
SetLevel
(
logrus
.
DebugLevel
)
apiLogPath
:=
"api.log"
logWriter
,
err
:=
rotatelogs
.
New
(
apiLogPath
+
".%Y-%m-%d-%H-%M.log"
,
rotatelogs
.
WithLinkName
(
apiLogPath
),
// 生成软链,指向最新日志文件
rotatelogs
.
WithMaxAge
(
7
*
24
*
time
.
Hour
),
// 文件最大保存时间
rotatelogs
.
WithRotationTime
(
24
*
time
.
Hour
),
// 日志切割时间间隔
)
writeMap
:=
lfshook
.
WriterMap
{
logrus
.
InfoLevel
:
logWriter
,
logrus
.
FatalLevel
:
logWriter
,
}
lfHook
:=
lfshook
.
NewHook
(
writeMap
,
&
logrus
.
JSONFormatter
{})
logClient
.
AddHook
(
lfHook
)
return
func
(
c
*
gin
.
Context
)
{
// 开始时间
start
:=
time
.
Now
()
...
...
@@ -50,7 +24,7 @@ func Logger() gin.HandlerFunc {
buf
:=
make
([]
byte
,
1024
)
n
,
_
:=
c
.
Request
.
Body
.
Read
(
buf
)
requestParams
:=
buf
[
0
:
n
]
logClient
.
Infof
(
"| %3d | %13v | %15s | %s %s |%s|"
,
qmlog
.
QMLog
.
Infof
(
"| %3d | %13v | %15s | %s %s |%s|"
,
statusCode
,
latency
,
clientIP
,
...
...
QMPlusServer/model/dbModel/user.go
浏览文件 @
3c16f8a3
...
...
@@ -4,7 +4,7 @@ import (
"github.com/jinzhu/gorm"
"github.com/pkg/errors"
uuid
"github.com/satori/go.uuid"
"main/init/
my
sql"
"main/init/
qm
sql"
"main/tools"
)
...
...
@@ -27,7 +27,7 @@ type User struct {
func
(
u
*
User
)
Regist
()
(
err
error
,
userInter
*
User
)
{
var
user
User
//判断用户名是否注册
findErr
:=
my
sql
.
DEFAULTDB
.
Where
(
"user_name = ?"
,
u
.
UserName
)
.
First
(
&
user
)
.
Error
findErr
:=
qm
sql
.
DEFAULTDB
.
Where
(
"user_name = ?"
,
u
.
UserName
)
.
First
(
&
user
)
.
Error
//err为nil表明读取到了 不能注册
if
findErr
==
nil
{
return
errors
.
New
(
"用户名已注册"
),
nil
...
...
@@ -35,7 +35,7 @@ func (u *User) Regist() (err error, userInter *User) {
// 否则 附加uuid 密码md5简单加密 注册
u
.
PassWord
=
tools
.
MD5V
(
u
.
PassWord
)
u
.
UUID
=
uuid
.
NewV4
()
err
=
my
sql
.
DEFAULTDB
.
Create
(
u
)
.
Error
err
=
qm
sql
.
DEFAULTDB
.
Create
(
u
)
.
Error
}
return
err
,
u
}
...
...
@@ -45,13 +45,13 @@ func (u *User) ChangePassWord(newPassWord string) (err error, userInter *User) {
var
user
User
//后期修改jwt+password模式
u
.
PassWord
=
tools
.
MD5V
(
u
.
PassWord
)
err
=
my
sql
.
DEFAULTDB
.
Where
(
"user_name = ? AND pass_word = ?"
,
u
.
UserName
,
u
.
PassWord
)
.
First
(
&
user
)
.
Update
(
"pass_word"
,
tools
.
MD5V
(
newPassWord
))
.
Error
err
=
qm
sql
.
DEFAULTDB
.
Where
(
"user_name = ? AND pass_word = ?"
,
u
.
UserName
,
u
.
PassWord
)
.
First
(
&
user
)
.
Update
(
"pass_word"
,
tools
.
MD5V
(
newPassWord
))
.
Error
return
err
,
u
}
//用户更新接口
func
(
u
*
User
)
UpdataUser
()
(
err
error
,
userInter
*
User
)
{
err
=
my
sql
.
DEFAULTDB
.
Create
(
u
)
.
Error
err
=
qm
sql
.
DEFAULTDB
.
Create
(
u
)
.
Error
return
err
,
u
}
...
...
@@ -59,6 +59,6 @@ func (u *User) UpdataUser() (err error, userInter *User) {
func
(
u
*
User
)
Login
()
(
err
error
,
userInter
*
User
)
{
var
user
User
u
.
PassWord
=
tools
.
MD5V
(
u
.
PassWord
)
err
=
my
sql
.
DEFAULTDB
.
Where
(
"user_name = ? AND pass_word = ?"
,
u
.
UserName
,
u
.
PassWord
)
.
First
(
&
user
)
.
Error
err
=
qm
sql
.
DEFAULTDB
.
Where
(
"user_name = ? AND pass_word = ?"
,
u
.
UserName
,
u
.
PassWord
)
.
First
(
&
user
)
.
Error
return
err
,
&
user
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录