diff --git a/go.mod b/go.mod index 23c63865..008d1e44 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/gobuffalo/packr/v2 v2.8.1 github.com/gorilla/websocket v1.4.2 github.com/robfig/cron/v3 v3.0.1 - github.com/shirou/gopsutil v3.20.11+incompatible + github.com/shirou/gopsutil v3.20.12+incompatible github.com/spf13/cobra v1.1.1 github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e // indirect diff --git a/go.sum b/go.sum index 27392c84..60607183 100644 --- a/go.sum +++ b/go.sum @@ -244,8 +244,8 @@ github.com/rogpeppe/go-internal v1.5.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/shirou/gopsutil v3.20.11+incompatible h1:LJr4ZQK4mPpIV5gOa4jCOKOGb4ty4DZO54I4FGqIpto= -github.com/shirou/gopsutil v3.20.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shirou/gopsutil v3.20.12+incompatible h1:6VEGkOXP/eP4o2Ilk8cSsX0PhOEfX6leqAnD+urrp9M= +github.com/shirou/gopsutil v3.20.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= diff --git a/web/controller/user.go b/web/controller/user.go index 669c4f5a..2c48f63c 100644 --- a/web/controller/user.go +++ b/web/controller/user.go @@ -9,22 +9,27 @@ import ( ) // UserList 获取用户列表 -func UserList(findUser string) *ResponseBody { +func UserList(requestUser string) *ResponseBody { responseBody := ResponseBody{Msg: "success"} defer TimeCost(time.Now(), &responseBody) mysql := core.GetMysql() userList, err := mysql.GetData() - if findUser != "" { + if err != nil { + responseBody.Msg = err.Error() + return &responseBody + } + if requestUser != "admin" { + findUser := false for _, user := range userList { - if user.Username == findUser { + if user.Username == requestUser { userList = []*core.User{user} + findUser = true break } } - } - if err != nil { - responseBody.Msg = err.Error() - return &responseBody + if !findUser { + userList = []*core.User{} + } } domain, port := trojan.GetDomainAndPort() responseBody.Data = map[string]interface{}{ diff --git a/web/web.go b/web/web.go index 64ad0a2f..8f846367 100644 --- a/web/web.go +++ b/web/web.go @@ -17,11 +17,7 @@ func userRouter(router *gin.Engine) { { user.GET("", func(c *gin.Context) { requestUser := RequestUsername(c) - if requestUser == "admin" { - c.JSON(200, controller.UserList("")) - } else { - c.JSON(200, controller.UserList(requestUser)) - } + c.JSON(200, controller.UserList(requestUser)) }) user.GET("/page", func(c *gin.Context) { curPageStr := c.DefaultQuery("curPage", "1")