Skip to content

Commit

Permalink
优化查询接口
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Jan 16, 2021
1 parent a767a42 commit e189721
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
19 changes: 12 additions & 7 deletions web/controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down
6 changes: 1 addition & 5 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e189721

Please sign in to comment.