From 5563d0d430dd77e6e57535277487982aa8d7a448 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 20 Apr 2026 08:26:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20staticcheck=20?= =?UTF-8?q?=E5=92=8C=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复所有 Yoda 条件错误 (ST1017) - 修复 error 格式错误 (ST1005) - 修复不必要的 blank identifier (QF1001) - 移除 tsc 重复编译,减少内存使用 - monaco-editor 改为动态导入 --- server/api/session.go | 28 ++++++++++++++-------------- server/api/term.go | 2 +- server/common/sets/set.go | 2 +- server/service/asset.go | 2 +- server/service/session.go | 2 +- server/sshd/ui.go | 2 +- server/sshd/writer.go | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/server/api/session.go b/server/api/session.go index 7ddb6a8bd..343ba4cf2 100644 --- a/server/api/session.go +++ b/server/api/session.go @@ -250,7 +250,7 @@ func (api SessionApi) SessionUploadEndpoint(c echo.Context) error { account, _ := GetCurrentAccount(c) _ = service.StorageLogService.Save(context.Background(), s.AssetId, sessionId, account.ID, nt.StorageLogActionUpload, remoteFile) - if "ssh" == s.Protocol { + if s.Protocol == "ssh" { nextSession := session.GlobalSessionManager.GetById(sessionId) if nextSession == nil { return errors.New("获取会话失败") @@ -280,7 +280,7 @@ func (api SessionApi) SessionUploadEndpoint(c echo.Context) error { return err } return Success(c, nil) - } else if "rdp" == s.Protocol { + } else if s.Protocol == "rdp" { if err := service.StorageService.StorageUpload(c, file, s.StorageId); err != nil { return err } @@ -302,7 +302,7 @@ func (api SessionApi) SessionEditEndpoint(c echo.Context) error { file := c.FormValue("file") fileContent := c.FormValue("fileContent") - if "ssh" == s.Protocol { + if s.Protocol == "ssh" { nextSession := session.GlobalSessionManager.GetById(sessionId) if nextSession == nil { return errors.New("获取会话失败") @@ -329,7 +329,7 @@ func (api SessionApi) SessionEditEndpoint(c echo.Context) error { return err } return Success(c, nil) - } else if "rdp" == s.Protocol { + } else if s.Protocol == "rdp" { if err := service.StorageService.StorageEdit(file, fileContent, s.StorageId); err != nil { return err } @@ -355,7 +355,7 @@ func (api SessionApi) SessionDownloadEndpoint(c echo.Context) error { // 获取带后缀的文件名称 filenameWithSuffix := path.Base(file) - if "ssh" == s.Protocol { + if s.Protocol == "ssh" { nextSession := session.GlobalSessionManager.GetById(sessionId) if nextSession == nil { return errors.New("获取会话失败") @@ -375,7 +375,7 @@ func (api SessionApi) SessionDownloadEndpoint(c echo.Context) error { } return c.Stream(http.StatusOK, echo.MIMEOctetStream, bytes.NewReader(buff.Bytes())) - } else if "rdp" == s.Protocol { + } else if s.Protocol == "rdp" { storageId := s.StorageId return service.StorageService.StorageDownload(c, file, storageId) } @@ -391,7 +391,7 @@ func (api SessionApi) SessionLsEndpoint(c echo.Context) error { } remoteDir := c.FormValue("dir") - if "ssh" == s.Protocol { + if s.Protocol == "ssh" { nextSession := session.GlobalSessionManager.GetById(sessionId) if nextSession == nil { return errors.New("获取会话失败") @@ -427,7 +427,7 @@ func (api SessionApi) SessionLsEndpoint(c echo.Context) error { } return Success(c, files) - } else if "rdp" == s.Protocol { + } else if s.Protocol == "rdp" { storageId := s.StorageId files, err := service.StorageService.StorageLs(remoteDir, storageId) if err != nil { @@ -454,7 +454,7 @@ func (api SessionApi) SessionMkDirEndpoint(c echo.Context) error { account, _ := GetCurrentAccount(c) _ = service.StorageLogService.Save(context.Background(), s.AssetId, sessionId, account.ID, nt.StorageLogActionMkdir, remoteDir) - if "ssh" == s.Protocol { + if s.Protocol == "ssh" { nextSession := session.GlobalSessionManager.GetById(sessionId) if nextSession == nil { return errors.New("获取会话失败") @@ -463,7 +463,7 @@ func (api SessionApi) SessionMkDirEndpoint(c echo.Context) error { return err } return Success(c, nil) - } else if "rdp" == s.Protocol { + } else if s.Protocol == "rdp" { storageId := s.StorageId if err := service.StorageService.StorageMkDir(remoteDir, storageId); err != nil { return err @@ -489,7 +489,7 @@ func (api SessionApi) SessionRmEndpoint(c echo.Context) error { account, _ := GetCurrentAccount(c) _ = service.StorageLogService.Save(context.Background(), s.AssetId, sessionId, account.ID, nt.StorageLogActionRm, file) - if "ssh" == s.Protocol { + if s.Protocol == "ssh" { nextSession := session.GlobalSessionManager.GetById(sessionId) if nextSession == nil { return errors.New("获取会话失败") @@ -524,7 +524,7 @@ func (api SessionApi) SessionRmEndpoint(c echo.Context) error { } return Success(c, nil) - } else if "rdp" == s.Protocol { + } else if s.Protocol == "rdp" { storageId := s.StorageId if err := service.StorageService.StorageRm(file, storageId); err != nil { return err @@ -551,7 +551,7 @@ func (api SessionApi) SessionRenameEndpoint(c echo.Context) error { account, _ := GetCurrentAccount(c) _ = service.StorageLogService.Save(context.Background(), s.AssetId, sessionId, account.ID, nt.StorageLogActionRename, oldName) - if "ssh" == s.Protocol { + if s.Protocol == "ssh" { nextSession := session.GlobalSessionManager.GetById(sessionId) if nextSession == nil { return errors.New("获取会话失败") @@ -564,7 +564,7 @@ func (api SessionApi) SessionRenameEndpoint(c echo.Context) error { } return Success(c, nil) - } else if "rdp" == s.Protocol { + } else if s.Protocol == "rdp" { storageId := s.StorageId if err := service.StorageService.StorageRename(oldName, newName, storageId); err != nil { return err diff --git a/server/api/term.go b/server/api/term.go index 864989120..8d9ff96de 100644 --- a/server/api/term.go +++ b/server/api/term.go @@ -100,7 +100,7 @@ func (api WebTerminalApi) SshEndpoint(c echo.Context) error { var xterm = "xterm-256color" var nextTerminal *term.NextTerminal - if "true" == attributes[nt.SocksProxyEnable] { + if attributes[nt.SocksProxyEnable] == "true" { nextTerminal, err = term.NewNextTerminalUseSocks(ip, port, username, password, privateKey, passphrase, rows, cols, recording, xterm, true, attributes[nt.SocksProxyHost], attributes[nt.SocksProxyPort], attributes[nt.SocksProxyUsername], attributes[nt.SocksProxyPassword]) } else { nextTerminal, err = term.NewNextTerminal(ip, port, username, password, privateKey, passphrase, rows, cols, recording, xterm, true) diff --git a/server/common/sets/set.go b/server/common/sets/set.go index cbcbba863..abe41e124 100644 --- a/server/common/sets/set.go +++ b/server/common/sets/set.go @@ -27,7 +27,7 @@ func (s *Set) Contains(key string) bool { func (s *Set) ToArray() []string { var keys []string - for key, _ := range s.data { + for key := range s.data { keys = append(keys, key) } return keys diff --git a/server/service/asset.go b/server/service/asset.go index e651b8c47..6ca59d511 100644 --- a/server/service/asset.go +++ b/server/service/asset.go @@ -131,7 +131,7 @@ func (s assetService) CheckStatus(asset *model.Asset, ip string, port int) (bool return false, err } - if "true" == attributes[nt.SocksProxyEnable] { + if attributes[nt.SocksProxyEnable] == "true" { socks5 := fmt.Sprintf("%s:%s", attributes[nt.SocksProxyHost], attributes[nt.SocksProxyPort]) auth := &proxy.Auth{ User: attributes[nt.SocksProxyUsername], diff --git a/server/service/session.go b/server/service/session.go index b05209719..2f137d72d 100644 --- a/server/service/session.go +++ b/server/service/session.go @@ -283,7 +283,7 @@ func (service sessionService) Create(clientIp, assetId, mode string, user *model if err != nil { return nil, err } - if "true" == attr[guacamole.EnableDrive] { + if attr[guacamole.EnableDrive] == "true" { fileSystem = "1" storageId = attr[guacamole.DrivePath] if storageId == "" { diff --git a/server/sshd/ui.go b/server/sshd/ui.go index 7308adb08..7a912795b 100644 --- a/server/sshd/ui.go +++ b/server/sshd/ui.go @@ -206,7 +206,7 @@ func (gui Gui) handleAccessAsset(sess ssh.Session, sessionId string) (err error) pty, winCh, isPty := (sess).Pty() if !isPty { - return errors.New("No PTY requested.\n") + return errors.New("no PTY requested") } recording := "" diff --git a/server/sshd/writer.go b/server/sshd/writer.go index 7e97f763a..6dc6fe2ba 100644 --- a/server/sshd/writer.go +++ b/server/sshd/writer.go @@ -40,7 +40,7 @@ func (w *Writer) Write(p []byte) (n int, err error) { if w.sz { // sz 会以 OO 结尾 - if "OO" == s { + if s == "OO" { w.sz = false } } else if w.rz {