From 4492d539935e2170611157ee4307145af8e76f0a Mon Sep 17 00:00:00 2001 From: Jrohy Date: Fri, 31 Jul 2020 20:15:50 +0800 Subject: [PATCH] fix bug --- core/mysql.go | 10 +++++----- web/controller/user.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/mysql.go b/core/mysql.go index d104a203..fdae2b67 100644 --- a/core/mysql.go +++ b/core/mysql.go @@ -239,7 +239,7 @@ func (mysql *Mysql) GetUserByPass(pass string) *User { } // PageList 通过分页获取用户记录 -func (mysql *Mysql) PageList(curPage int, pageSize int) *PageQuery { +func (mysql *Mysql) PageList(curPage int, pageSize int) (*PageQuery, error) { var ( total int dataList []*User @@ -247,7 +247,7 @@ func (mysql *Mysql) PageList(curPage int, pageSize int) *PageQuery { db := mysql.GetDB() if db == nil { - return nil + return nil, errors.New("连接mysql失败") } defer db.Close() offset := (curPage - 1) * pageSize @@ -255,7 +255,7 @@ func (mysql *Mysql) PageList(curPage int, pageSize int) *PageQuery { rows, err := db.Query(querySQL) if err != nil { fmt.Println(err) - return nil + return nil, err } defer rows.Close() for rows.Next() { @@ -270,7 +270,7 @@ func (mysql *Mysql) PageList(curPage int, pageSize int) *PageQuery { ) if err := rows.Scan(&id, &username, &originPass, &passShow, "a, &download, &upload); err != nil { fmt.Println(err) - return nil + return nil, err } dataList = append(dataList, &User{ID: id, Username: username, Password: passShow, Download: download, Upload: upload, Quota: quota}) } @@ -281,7 +281,7 @@ func (mysql *Mysql) PageList(curPage int, pageSize int) *PageQuery { Total: total, DataList: dataList, PageNum: (total + pageSize - 1) / pageSize, - } + }, nil } // GetData 获取用户记录 diff --git a/web/controller/user.go b/web/controller/user.go index a5638c87..4ff94537 100644 --- a/web/controller/user.go +++ b/web/controller/user.go @@ -40,9 +40,9 @@ func PageUserList(curPage int, pageSize int) *ResponseBody { responseBody := ResponseBody{Msg: "success"} defer TimeCost(time.Now(), &responseBody) mysql := core.GetMysql() - pageData := mysql.PageList(curPage, pageSize) - if pageData == nil { - responseBody.Msg = "连接mysql失败!" + pageData, err := mysql.PageList(curPage, pageSize) + if err != nil { + responseBody.Msg = err.Error() return &responseBody } domain, port := trojan.GetDomainAndPort()