style(be):使用goimport 格式化代码并添加golangci

This commit is contained in:
neverteaser
2021-03-16 14:00:03 +08:00
committed by dushixiang
parent 88b0200095
commit d366cbd00d
40 changed files with 244 additions and 124 deletions

View File

@ -1,12 +1,13 @@
package api
import (
"strings"
"time"
"next-terminal/pkg/global"
"next-terminal/pkg/model"
"next-terminal/pkg/totp"
"next-terminal/pkg/utils"
"strings"
"time"
"github.com/labstack/echo/v4"
)

View File

@ -5,12 +5,14 @@ import (
"encoding/csv"
"encoding/json"
"errors"
"github.com/labstack/echo/v4"
"strconv"
"strings"
"next-terminal/pkg/constant"
"next-terminal/pkg/model"
"next-terminal/pkg/utils"
"strconv"
"strings"
"github.com/labstack/echo/v4"
)
func AssetCreateEndpoint(c echo.Context) error {

View File

@ -2,11 +2,13 @@ package api
import (
"errors"
"github.com/labstack/echo/v4"
"next-terminal/pkg/model"
"next-terminal/pkg/utils"
"strconv"
"strings"
"next-terminal/pkg/model"
"next-terminal/pkg/utils"
"github.com/labstack/echo/v4"
)
func CommandCreateEndpoint(c echo.Context) error {

View File

@ -2,12 +2,14 @@ package api
import (
"errors"
"github.com/labstack/echo/v4"
"strconv"
"strings"
"next-terminal/pkg/constant"
"next-terminal/pkg/model"
"next-terminal/pkg/utils"
"strconv"
"strings"
"github.com/labstack/echo/v4"
)
func CredentialAllEndpoint(c echo.Context) error {

View File

@ -1,11 +1,13 @@
package api
import (
"github.com/labstack/echo/v4"
"next-terminal/pkg/model"
"next-terminal/pkg/utils"
"strconv"
"strings"
"next-terminal/pkg/model"
"next-terminal/pkg/utils"
"github.com/labstack/echo/v4"
)
func JobCreateEndpoint(c echo.Context) error {

View File

@ -1,11 +1,14 @@
package api
import (
"github.com/labstack/echo/v4"
"next-terminal/pkg/global"
"next-terminal/pkg/model"
"strconv"
"strings"
"next-terminal/pkg/global"
"next-terminal/pkg/model"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
)
func LoginLogPagingEndpoint(c echo.Context) error {
@ -32,7 +35,9 @@ func LoginLogDeleteEndpoint(c echo.Context) error {
for i := range split {
token := split[i]
global.Cache.Delete(token)
model.Logout(token)
if err := model.Logout(token); err != nil {
logrus.WithError(err).Error("Cache Delete Failed")
}
}
if err := model.DeleteLoginLogByIdIn(split); err != nil {
return err

View File

@ -2,14 +2,16 @@ package api
import (
"fmt"
"github.com/labstack/echo/v4"
"net"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/utils"
"regexp"
"strings"
"time"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/utils"
"github.com/labstack/echo/v4"
)
func ErrorHandler(next echo.HandlerFunc) echo.HandlerFunc {

View File

@ -1,9 +1,10 @@
package api
import (
"github.com/labstack/echo/v4"
"next-terminal/pkg/constant"
"next-terminal/pkg/model"
"github.com/labstack/echo/v4"
)
type Counter struct {

View File

@ -3,9 +3,11 @@ package api
import (
"errors"
"fmt"
"next-terminal/pkg/model"
"github.com/labstack/echo/v4"
"gorm.io/gorm"
"next-terminal/pkg/model"
)
func PropertyGetEndpoint(c echo.Context) error {

View File

@ -1,8 +1,9 @@
package api
import (
"github.com/labstack/echo/v4"
"next-terminal/pkg/model"
"github.com/labstack/echo/v4"
)
type RU struct {

View File

@ -2,6 +2,7 @@ package api
import (
"net/http"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/log"

View File

@ -1,12 +1,14 @@
package api
import (
"github.com/labstack/echo/v4"
"strconv"
"strings"
"next-terminal/pkg/global"
"next-terminal/pkg/model"
"next-terminal/pkg/utils"
"strconv"
"strings"
"github.com/labstack/echo/v4"
)
func SecurityCreateEndpoint(c echo.Context) error {
@ -33,7 +35,7 @@ func ReloadAccessSecurity() error {
if err != nil {
return err
}
if rules != nil && len(rules) > 0 {
if rules != nil {
var securities []*global.Security
for i := 0; i < len(rules); i++ {
rule := global.Security{

View File

@ -4,21 +4,23 @@ import (
"bytes"
"errors"
"fmt"
"github.com/labstack/echo/v4"
"github.com/pkg/sftp"
"github.com/sirupsen/logrus"
"io"
"io/ioutil"
"net/http"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/model"
"next-terminal/pkg/utils"
"os"
"path"
"strconv"
"strings"
"sync"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/model"
"next-terminal/pkg/utils"
"github.com/labstack/echo/v4"
"github.com/pkg/sftp"
"github.com/sirupsen/logrus"
)
func SessionPagingEndpoint(c echo.Context) error {

View File

@ -2,19 +2,21 @@ package api
import (
"encoding/json"
"github.com/gorilla/websocket"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
"net/http"
"path"
"strconv"
"time"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/guacd"
"next-terminal/pkg/model"
"next-terminal/pkg/term"
"next-terminal/pkg/utils"
"path"
"strconv"
"time"
"github.com/gorilla/websocket"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
)
var UpGrader = websocket.Upgrader{

View File

@ -2,15 +2,17 @@ package api
import (
"errors"
"github.com/gorilla/websocket"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
"path"
"strconv"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/guacd"
"next-terminal/pkg/model"
"path"
"strconv"
"github.com/gorilla/websocket"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
)
const (
@ -98,7 +100,6 @@ func TunEndpoint(c echo.Context) error {
configuration.SetParameter(guacd.DisableBitmapCaching, propertyMap[guacd.DisableBitmapCaching])
configuration.SetParameter(guacd.DisableOffscreenCaching, propertyMap[guacd.DisableOffscreenCaching])
configuration.SetParameter(guacd.DisableGlyphCaching, propertyMap[guacd.DisableGlyphCaching])
break
case "ssh":
if len(session.PrivateKey) > 0 && session.PrivateKey != "-" {
configuration.SetParameter("username", session.Username)
@ -114,11 +115,9 @@ func TunEndpoint(c echo.Context) error {
configuration.SetParameter(guacd.ColorScheme, propertyMap[guacd.ColorScheme])
configuration.SetParameter(guacd.Backspace, propertyMap[guacd.Backspace])
configuration.SetParameter(guacd.TerminalType, propertyMap[guacd.TerminalType])
break
case "vnc":
configuration.SetParameter("username", session.Username)
configuration.SetParameter("password", session.Password)
break
case "telnet":
configuration.SetParameter("username", session.Username)
configuration.SetParameter("password", session.Password)
@ -128,7 +127,6 @@ func TunEndpoint(c echo.Context) error {
configuration.SetParameter(guacd.ColorScheme, propertyMap[guacd.ColorScheme])
configuration.SetParameter(guacd.Backspace, propertyMap[guacd.Backspace])
configuration.SetParameter(guacd.TerminalType, propertyMap[guacd.TerminalType])
break
case "kubernetes":
configuration.SetParameter(guacd.FontSize, propertyMap[guacd.FontSize])
@ -136,6 +134,9 @@ func TunEndpoint(c echo.Context) error {
configuration.SetParameter(guacd.ColorScheme, propertyMap[guacd.ColorScheme])
configuration.SetParameter(guacd.Backspace, propertyMap[guacd.Backspace])
configuration.SetParameter(guacd.TerminalType, propertyMap[guacd.TerminalType])
default:
logrus.WithField("configuration.Protocol", configuration.Protocol).Error("UnSupport Protocol")
return Fail(c, 400, "不支持的协议")
}
configuration.SetParameter("hostname", session.IP)
@ -209,7 +210,7 @@ func TunEndpoint(c echo.Context) error {
}
go func() {
for true {
for {
instruction, err := tunnel.Read()
if err != nil {
if connectionId == "" {
@ -230,7 +231,7 @@ func TunEndpoint(c echo.Context) error {
}
}()
for true {
for {
_, message, err := ws.ReadMessage()
if err != nil {
if connectionId == "" {

View File

@ -1,12 +1,14 @@
package api
import (
"github.com/labstack/echo/v4"
"strconv"
"strings"
"next-terminal/pkg/global"
"next-terminal/pkg/model"
"next-terminal/pkg/utils"
"strconv"
"strings"
"github.com/labstack/echo/v4"
)
type UserGroup struct {

View File

@ -1,12 +1,15 @@
package api
import (
"github.com/labstack/echo/v4"
"strconv"
"strings"
"next-terminal/pkg/global"
"next-terminal/pkg/model"
"next-terminal/pkg/utils"
"strconv"
"strings"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
)
func UserCreateEndpoint(c echo.Context) error {
@ -87,12 +90,15 @@ func UserDeleteEndpoint(c echo.Context) error {
if err != nil {
return err
}
if loginLogs != nil && len(loginLogs) > 0 {
for j := range loginLogs {
global.Cache.Delete(loginLogs[j].ID)
model.Logout(loginLogs[j].ID)
for j := range loginLogs {
global.Cache.Delete(loginLogs[j].ID)
if err := model.Logout(loginLogs[j].ID); err != nil {
logrus.WithError(err).WithField("id:", loginLogs[j].ID).Error("Cache Deleted Error")
return Fail(c, 500, "强制下线错误")
}
}
// 删除用户
model.DeleteUserById(userId)
}