From ea48bd3da2fb7f2b80b38b0526d37e4b22a4c447 Mon Sep 17 00:00:00 2001 From: 1mtrue Date: Tue, 16 Mar 2021 17:22:16 +0800 Subject: [PATCH] =?UTF-8?q?style(be):golangci-lint=20github=20action=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0timeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/golangci-lint.yml | 3 ++- main.go | 2 +- pkg/api/security.go | 2 +- pkg/handle/runner.go | 4 ++-- pkg/model/asset.go | 4 ++-- pkg/model/credential.go | 2 +- pkg/model/job.go | 4 ++-- pkg/model/resource-sharer.go | 2 +- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index a3a4a90..35969fb 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -18,4 +18,5 @@ jobs: uses: golangci/golangci-lint-action@v2 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.29 \ No newline at end of file + version: v1.29 + args: --timeout=10m diff --git a/main.go b/main.go index d782322..ef7781e 100644 --- a/main.go +++ b/main.go @@ -229,7 +229,7 @@ func Run() error { if err != nil { return err } - if jobs == nil { + if len(jobs) == 0 { job := model.Job{ ID: utils.UUID(), Name: "资产状态检测", diff --git a/pkg/api/security.go b/pkg/api/security.go index 52fe8aa..e7e2874 100644 --- a/pkg/api/security.go +++ b/pkg/api/security.go @@ -35,7 +35,7 @@ func ReloadAccessSecurity() error { if err != nil { return err } - if rules != nil { + if len(rules) > 0 { var securities []*global.Security for i := 0; i < len(rules); i++ { rule := global.Security{ diff --git a/pkg/handle/runner.go b/pkg/handle/runner.go index e6f3fc7..0ecaa4a 100644 --- a/pkg/handle/runner.go +++ b/pkg/handle/runner.go @@ -20,7 +20,7 @@ func RunTicker() { go func() { for range unUsedSessionTicker.C { sessions, _ := model.FindSessionByStatusIn([]string{constant.NoConnect, constant.Connecting}) - if sessions != nil { + if len(sessions) > 0 { now := time.Now() for i := range sessions { if now.Sub(sessions[i].ConnectedTime.Time) > time.Hour*1 { @@ -53,7 +53,7 @@ func RunTicker() { return } - if sessions != nil { + if len(sessions) > 0 { var sessionIds []string for i := range sessions { sessionIds = append(sessionIds, sessions[i].ID) diff --git a/pkg/model/asset.go b/pkg/model/asset.go index 7a102a1..6f46eb3 100644 --- a/pkg/model/asset.go +++ b/pkg/model/asset.go @@ -95,7 +95,7 @@ func FindPageAsset(pageIndex, pageSize int, name, protocol, tags string, account return nil, 0, err } - if userGroupIds != nil { + if len(userGroupIds) > 0 { db = db.Or("resource_sharers.user_group_id in ?", userGroupIds) dbCounter = dbCounter.Or("resource_sharers.user_group_id in ?", userGroupIds) } @@ -210,7 +210,7 @@ func CountAssetByUserId(userId string) (total int64, err error) { return 0, err } - if userGroupIds != nil { + if len(userGroupIds) > 0 { db = db.Or("resource_sharers.user_group_id in ?", userGroupIds) } err = db.Find(&Asset{}).Count(&total).Error diff --git a/pkg/model/credential.go b/pkg/model/credential.go index ce4947d..f198f09 100644 --- a/pkg/model/credential.go +++ b/pkg/model/credential.go @@ -123,7 +123,7 @@ func CountCredentialByUserId(userId string) (total int64, err error) { return 0, err } - if userGroupIds != nil { + if len(userGroupIds) > 0 { db = db.Or("resource_sharers.user_group_id in ?", userGroupIds) } err = db.Find(&Credential{}).Count(&total).Error diff --git a/pkg/model/job.go b/pkg/model/job.go index 4a6ab2b..f7562f5 100644 --- a/pkg/model/job.go +++ b/pkg/model/job.go @@ -199,7 +199,7 @@ func (r CheckAssetStatusJob) Run() { assets, _ = FindAssetByIds(strings.Split(r.ResourceIds, ",")) } - if assets == nil { + if len(assets) == 0 { return } @@ -257,7 +257,7 @@ func (r ShellJob) Run() { assets, _ = FindAssetByProtocolAndIds("ssh", strings.Split(r.ResourceIds, ",")) } - if assets == nil { + if len(assets) == 0 { return } diff --git a/pkg/model/resource-sharer.go b/pkg/model/resource-sharer.go index 1049511..442c7c5 100644 --- a/pkg/model/resource-sharer.go +++ b/pkg/model/resource-sharer.go @@ -175,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 { + if len(groupIds) > 0 { db = db.Or("user_group_id in ?", groupIds) } err = db.Find(&sharerAssetIds).Error