diff --git a/server/cli/cli.go b/server/cli/cli.go index 619764a..655ca43 100644 --- a/server/cli/cli.go +++ b/server/cli/cli.go @@ -4,12 +4,13 @@ import ( "context" "crypto/md5" "fmt" - "next-terminal/server/env" - "next-terminal/server/service" + "next-terminal/server/constant" + "next-terminal/server/env" "next-terminal/server/log" "next-terminal/server/model" "next-terminal/server/repository" + "next-terminal/server/service" "next-terminal/server/utils" "gorm.io/gorm" @@ -65,7 +66,7 @@ func (cli Cli) ChangeEncryptionKey(oldEncryptionKey, newEncryptionKey string) er newPassword := []byte(fmt.Sprintf("%x", md5.Sum([]byte(newEncryptionKey)))) return env.GetDB().Transaction(func(tx *gorm.DB) error { - c := context.WithValue(context.TODO(), "db", tx) + c := context.WithValue(context.TODO(), constant.DB, tx) credentials, err := repository.CredentialRepository.FindAll(c) if err != nil { return err diff --git a/server/constant/const.go b/server/constant/const.go index 00281e3..0f05c2a 100644 --- a/server/constant/const.go +++ b/server/constant/const.go @@ -19,8 +19,10 @@ const ( const Token = "X-Auth-Token" +type Key string + const ( - DB = "db" + DB Key = "db" SSH = "ssh" RDP = "rdp" diff --git a/server/service/backup.go b/server/service/backup.go index 4b6ca5b..3eef961 100644 --- a/server/service/backup.go +++ b/server/service/backup.go @@ -220,7 +220,7 @@ func (service backupService) Import(backup *dto.Backup) error { } } - var accessGatewayIdMapping = make(map[string]string, 0) + var accessGatewayIdMapping = make(map[string]string) if len(backup.AccessGateways) > 0 { for _, item := range backup.AccessGateways { oldId := item.ID @@ -244,7 +244,7 @@ func (service backupService) Import(backup *dto.Backup) error { } } - var credentialIdMapping = make(map[string]string, 0) + var credentialIdMapping = make(map[string]string) if len(backup.Credentials) > 0 { for _, item := range backup.Credentials { oldId := item.ID @@ -257,7 +257,7 @@ func (service backupService) Import(backup *dto.Backup) error { } } - var assetIdMapping = make(map[string]string, 0) + var assetIdMapping = make(map[string]string) if len(backup.Assets) > 0 { for _, m := range backup.Assets { data, err := json.Marshal(m) diff --git a/server/service/user.go b/server/service/user.go index 2028cce..b63863e 100644 --- a/server/service/user.go +++ b/server/service/user.go @@ -3,6 +3,7 @@ package service import ( "errors" "fmt" + "strings" "next-terminal/server/constant" "next-terminal/server/dto" @@ -12,7 +13,6 @@ import ( "next-terminal/server/model" "next-terminal/server/repository" "next-terminal/server/utils" - "strings" "golang.org/x/net/context" "gorm.io/gorm" diff --git a/server/sshd/ui.go b/server/sshd/ui.go index d87f296..a59cc35 100644 --- a/server/sshd/ui.go +++ b/server/sshd/ui.go @@ -5,6 +5,9 @@ import ( "errors" "fmt" "io" + "path" + "strings" + "next-terminal/server/api" "next-terminal/server/config" "next-terminal/server/constant" @@ -18,8 +21,6 @@ import ( "next-terminal/server/term" "next-terminal/server/totp" "next-terminal/server/utils" - "path" - "strings" "github.com/gliderlabs/ssh" "github.com/manifoldco/promptui" diff --git a/server/term/next_terminal.go b/server/term/next_terminal.go index 3be9d44..2029fdc 100644 --- a/server/term/next_terminal.go +++ b/server/term/next_terminal.go @@ -22,7 +22,7 @@ func NewNextTerminal(ip string, port int, username, password, privateKey, passph if err != nil { return nil, err } - return newNT(err, sshClient, pipe, recording, term, rows, cols) + return newNT(sshClient, pipe, recording, term, rows, cols) } func NewNextTerminalUseSocks(ip string, port int, username, password, privateKey, passphrase string, rows, cols int, recording, term string, pipe bool, socksProxyHost, socksProxyPort, socksProxyUsername, socksProxyPassword string) (*NextTerminal, error) { @@ -30,10 +30,10 @@ func NewNextTerminalUseSocks(ip string, port int, username, password, privateKey if err != nil { return nil, err } - return newNT(err, sshClient, pipe, recording, term, rows, cols) + return newNT(sshClient, pipe, recording, term, rows, cols) } -func newNT(err error, sshClient *ssh.Client, pipe bool, recording string, term string, rows int, cols int) (*NextTerminal, error) { +func newNT(sshClient *ssh.Client, pipe bool, recording string, term string, rows int, cols int) (*NextTerminal, error) { sshSession, err := sshClient.NewSession() if err != nil { return nil, err diff --git a/server/utils/guacamole.go b/server/utils/guacamole.go index 3173ce9..dc917cd 100644 --- a/server/utils/guacamole.go +++ b/server/utils/guacamole.go @@ -2,9 +2,11 @@ package utils import ( "encoding/base64" - "github.com/gorilla/websocket" - "next-terminal/server/guacd" "strconv" + + "next-terminal/server/guacd" + + "github.com/gorilla/websocket" ) func Disconnect(ws *websocket.Conn, code int, reason string) {