修改代码符合规范

This commit is contained in:
dushixiang
2022-01-23 18:09:31 +08:00
parent a372e8ae8c
commit d8377bf06c
7 changed files with 21 additions and 15 deletions

View File

@ -4,12 +4,13 @@ import (
"context" "context"
"crypto/md5" "crypto/md5"
"fmt" "fmt"
"next-terminal/server/env"
"next-terminal/server/service"
"next-terminal/server/constant"
"next-terminal/server/env"
"next-terminal/server/log" "next-terminal/server/log"
"next-terminal/server/model" "next-terminal/server/model"
"next-terminal/server/repository" "next-terminal/server/repository"
"next-terminal/server/service"
"next-terminal/server/utils" "next-terminal/server/utils"
"gorm.io/gorm" "gorm.io/gorm"
@ -65,7 +66,7 @@ func (cli Cli) ChangeEncryptionKey(oldEncryptionKey, newEncryptionKey string) er
newPassword := []byte(fmt.Sprintf("%x", md5.Sum([]byte(newEncryptionKey)))) newPassword := []byte(fmt.Sprintf("%x", md5.Sum([]byte(newEncryptionKey))))
return env.GetDB().Transaction(func(tx *gorm.DB) error { 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) credentials, err := repository.CredentialRepository.FindAll(c)
if err != nil { if err != nil {
return err return err

View File

@ -19,8 +19,10 @@ const (
const Token = "X-Auth-Token" const Token = "X-Auth-Token"
type Key string
const ( const (
DB = "db" DB Key = "db"
SSH = "ssh" SSH = "ssh"
RDP = "rdp" RDP = "rdp"

View File

@ -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 { if len(backup.AccessGateways) > 0 {
for _, item := range backup.AccessGateways { for _, item := range backup.AccessGateways {
oldId := item.ID 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 { if len(backup.Credentials) > 0 {
for _, item := range backup.Credentials { for _, item := range backup.Credentials {
oldId := item.ID 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 { if len(backup.Assets) > 0 {
for _, m := range backup.Assets { for _, m := range backup.Assets {
data, err := json.Marshal(m) data, err := json.Marshal(m)

View File

@ -3,6 +3,7 @@ package service
import ( import (
"errors" "errors"
"fmt" "fmt"
"strings"
"next-terminal/server/constant" "next-terminal/server/constant"
"next-terminal/server/dto" "next-terminal/server/dto"
@ -12,7 +13,6 @@ import (
"next-terminal/server/model" "next-terminal/server/model"
"next-terminal/server/repository" "next-terminal/server/repository"
"next-terminal/server/utils" "next-terminal/server/utils"
"strings"
"golang.org/x/net/context" "golang.org/x/net/context"
"gorm.io/gorm" "gorm.io/gorm"

View File

@ -5,6 +5,9 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"path"
"strings"
"next-terminal/server/api" "next-terminal/server/api"
"next-terminal/server/config" "next-terminal/server/config"
"next-terminal/server/constant" "next-terminal/server/constant"
@ -18,8 +21,6 @@ import (
"next-terminal/server/term" "next-terminal/server/term"
"next-terminal/server/totp" "next-terminal/server/totp"
"next-terminal/server/utils" "next-terminal/server/utils"
"path"
"strings"
"github.com/gliderlabs/ssh" "github.com/gliderlabs/ssh"
"github.com/manifoldco/promptui" "github.com/manifoldco/promptui"

View File

@ -22,7 +22,7 @@ func NewNextTerminal(ip string, port int, username, password, privateKey, passph
if err != nil { if err != nil {
return nil, err 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) { 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 { if err != nil {
return nil, err 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() sshSession, err := sshClient.NewSession()
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -2,9 +2,11 @@ package utils
import ( import (
"encoding/base64" "encoding/base64"
"github.com/gorilla/websocket"
"next-terminal/server/guacd"
"strconv" "strconv"
"next-terminal/server/guacd"
"github.com/gorilla/websocket"
) )
func Disconnect(ws *websocket.Conn, code int, reason string) { func Disconnect(ws *websocket.Conn, code int, reason string) {