From 2f56241da1a1d911b20fcc0914b81282b74cef23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Fri, 14 Jun 2024 11:30:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E5=8A=A8pureftpd=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/plugins/pureftpd_controller.go | 14 +++++--------- types/pureftpd.go | 6 ++++++ 2 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 types/pureftpd.go diff --git a/app/http/controllers/plugins/pureftpd_controller.go b/app/http/controllers/plugins/pureftpd_controller.go index 40a11de5..fa87fec2 100644 --- a/app/http/controllers/plugins/pureftpd_controller.go +++ b/app/http/controllers/plugins/pureftpd_controller.go @@ -9,16 +9,12 @@ import ( "github.com/TheTNB/panel/app/http/controllers" "github.com/TheTNB/panel/pkg/tools" + "github.com/TheTNB/panel/types" ) type PureFtpdController struct { } -type User struct { - Username string `json:"username"` - Path string `json:"path"` -} - func NewPureFtpdController() *PureFtpdController { return &PureFtpdController{} } @@ -29,19 +25,19 @@ func (r *PureFtpdController) List(ctx http.Context) http.Response { if err != nil { return controllers.Success(ctx, http.Json{ "total": 0, - "items": []User{}, + "items": []types.PureFtpdUser{}, }) } listArr := strings.Split(listRaw, "\n") - var users []User + var users []types.PureFtpdUser for _, v := range listArr { if len(v) == 0 { continue } match := regexp.MustCompile(`(\S+)\s+(\S+)`).FindStringSubmatch(v) - users = append(users, User{ + users = append(users, types.PureFtpdUser{ Username: match[1], Path: strings.Replace(match[2], "/./", "/", 1), }) @@ -54,7 +50,7 @@ func (r *PureFtpdController) List(ctx http.Context) http.Response { if startIndex > len(users) { return controllers.Success(ctx, http.Json{ "total": 0, - "items": []User{}, + "items": []types.PureFtpdUser{}, }) } if endIndex > len(users) { diff --git a/types/pureftpd.go b/types/pureftpd.go new file mode 100644 index 00000000..d1208bff --- /dev/null +++ b/types/pureftpd.go @@ -0,0 +1,6 @@ +package types + +type PureFtpdUser struct { + Username string `json:"username"` + Path string `json:"path"` +}