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

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

View File

@ -1,10 +1,11 @@
package model
import (
"strings"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/utils"
"strings"
)
type Asset struct {
@ -94,7 +95,7 @@ func FindPageAsset(pageIndex, pageSize int, name, protocol, tags string, account
return nil, 0, err
}
if userGroupIds != nil && len(userGroupIds) > 0 {
if userGroupIds != nil {
db = db.Or("resource_sharers.user_group_id in ?", userGroupIds)
dbCounter = dbCounter.Or("resource_sharers.user_group_id in ?", userGroupIds)
}
@ -209,7 +210,7 @@ func CountAssetByUserId(userId string) (total int64, err error) {
return 0, err
}
if userGroupIds != nil && len(userGroupIds) > 0 {
if userGroupIds != nil {
db = db.Or("resource_sharers.user_group_id in ?", userGroupIds)
}
err = db.Find(&Asset{}).Count(&total).Error

View File

@ -2,12 +2,14 @@ package model
import (
"fmt"
"github.com/labstack/echo/v4"
"gorm.io/gorm"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/guacd"
"next-terminal/pkg/utils"
"github.com/labstack/echo/v4"
"gorm.io/gorm"
)
type AssetAttribute struct {

View File

@ -123,7 +123,7 @@ func CountCredentialByUserId(userId string) (total int64, err error) {
return 0, err
}
if userGroupIds != nil && len(userGroupIds) > 0 {
if userGroupIds != nil {
db = db.Or("resource_sharers.user_group_id in ?", userGroupIds)
}
err = db.Find(&Credential{}).Count(&total).Error

View File

@ -4,14 +4,16 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/robfig/cron/v3"
"github.com/sirupsen/logrus"
"strings"
"time"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/term"
"next-terminal/pkg/utils"
"strings"
"time"
"github.com/robfig/cron/v3"
"github.com/sirupsen/logrus"
)
type Job struct {
@ -197,7 +199,7 @@ func (r CheckAssetStatusJob) Run() {
assets, _ = FindAssetByIds(strings.Split(r.ResourceIds, ","))
}
if assets == nil || len(assets) == 0 {
if assets == nil {
return
}
@ -255,7 +257,7 @@ func (r ShellJob) Run() {
assets, _ = FindAssetByProtocolAndIds("ssh", strings.Split(r.ResourceIds, ","))
}
if assets == nil || len(assets) == 0 {
if assets == nil {
return
}

View File

@ -1,9 +1,10 @@
package model
import (
"github.com/sirupsen/logrus"
"next-terminal/pkg/global"
"next-terminal/pkg/utils"
"github.com/sirupsen/logrus"
)
type LoginLog struct {

View File

@ -1,12 +1,14 @@
package model
import (
"github.com/jordan-wright/email"
"github.com/sirupsen/logrus"
"net/smtp"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/guacd"
"github.com/jordan-wright/email"
"github.com/sirupsen/logrus"
)
type Property struct {

View File

@ -1,10 +1,12 @@
package model
import (
"github.com/labstack/echo/v4"
"gorm.io/gorm"
"next-terminal/pkg/global"
"next-terminal/pkg/utils"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
"gorm.io/gorm"
)
type ResourceSharer struct {
@ -117,15 +119,22 @@ func AddSharerResources(userGroupId, userId, resourceType string, resourceIds []
switch resourceType {
case "asset":
resource := Asset{}
err = tx.Where("id = ?", resourceId).First(&resource).Error
if err = tx.Where("id = ?", resourceId).First(&resource).Error; err != nil {
return errors.Wrap(err, "find asset fail")
}
owner = resource.Owner
case "command":
resource := Command{}
err = tx.Where("id = ?", resourceId).First(&resource).Error
if err = tx.Where("id = ?", resourceId).First(&resource).Error; err != nil {
return errors.Wrap(err, "find command fail")
}
owner = resource.Owner
case "credential":
resource := Credential{}
err = tx.Where("id = ?", resourceId).First(&resource).Error
if err = tx.Where("id = ?", resourceId).First(&resource).Error; err != nil {
return errors.Wrap(err, "find credential fail")
}
owner = resource.Owner
}
@ -166,7 +175,7 @@ func FindAssetIdsByUserId(userId string) (assetIds []string, err error) {
}
db := global.DB.Table("resource_sharers").Select("resource_id").Where("user_id = ?", userId)
if groupIds != nil && len(groupIds) > 0 {
if groupIds != nil {
db = db.Or("user_group_id in ?", groupIds)
}
err = db.Find(&sharerAssetIds).Error

View File

@ -1,12 +1,13 @@
package model
import (
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/utils"
"os"
"path"
"time"
"next-terminal/pkg/constant"
"next-terminal/pkg/global"
"next-terminal/pkg/utils"
)
type Session struct {

View File

@ -1,9 +1,10 @@
package model
import (
"gorm.io/gorm"
"next-terminal/pkg/global"
"next-terminal/pkg/utils"
"gorm.io/gorm"
)
type UserGroup struct {

View File

@ -1,9 +1,10 @@
package model
import (
"reflect"
"next-terminal/pkg/global"
"next-terminal/pkg/utils"
"reflect"
)
type User struct {