Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: refine lint #14

Merged
merged 8 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,3 @@ jobs:

- name: Test
run: make test

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.0
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: lint
on: [push, pull_request]
jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup go
uses: actions/setup-go@v3
with:
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.2
- name: go mod tidy check
uses: katexochen/go-tidy-check@v2
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ build/initContainer/bscp
build/sidecar/bscp
build_local.sh
/bscp
/bscp.exe
/bscp.exe
cover.out
78 changes: 78 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
run:
timeout: 5m

issues:
# 显示所有 issue
max-issues-per-linter: 0
max-same-issues: 0
exclude-use-default: false

linters:
disable-all: true
enable:
# enable by default
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused

# custom
- goconst
- gocyclo
- gofmt
- goheader
- goimports
- gosec
- misspell
- nakedret
- revive
- unconvert
- unparam

linters-settings:
# 只开启特定的规则
errcheck:
exclude-functions:
- (*os.File).Close
- (io.Closer).Close
- os.RemoveAll
govet:
check-shadowing: true
gocyclo:
min-complexity: 30
gosec:
includes:
- G201 # SQL query construction using format string
- G202 # SQL query construction using string concatenation
- G101 # Look for hard coded credentials
- G401 # Detect the usage of DES, RC4, MD5 or SHA1
- G402 # Look for bad TLS connection settings
- G403 # Ensure minimum RSA key length of 2048 bits
- G404 # Insecure random number source (rand)
- G504 # Import blocklist: net/http/cgi
goheader:
template: |-
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
goimports:
local-prefixes: github.com/TencentBlueKing/bscp-go
misspell:
locale: US
revive:
rules:
- name: exported
severity: warning
disabled: false
arguments:
- checkPrivateReceivers
- sayRepetitiveInsteadOfStutters
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export LDVersionFLAG = "-X bscp.io/pkg/version.VERSION=${VERSION} \
-X bscp.io/pkg/version.GITHASH=${GITHASH} \
-X bscp.io/pkg/version.DEBUG=${DEBUG}"

.PHONY: lint
lint:
@golangci-lint run ./...

.PHONY: build_initContainer
build_initContainer:
${GOBUILD} -ldflags ${LDVersionFLAG} -o build/initContainer/bscp cli/main.go
Expand Down
2 changes: 2 additions & 0 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (

var defaultCachePath = "/tmp/bk-bscp"
var instance *Cache

// Enable define whether to enable local cache
var Enable bool

// Cache is the bscp sdk cache
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
"fmt"
"strings"

"github.com/spf13/viper"

"github.com/TencentBlueKing/bscp-go/cli/config"
"github.com/TencentBlueKing/bscp-go/cli/constant"
"github.com/spf13/viper"
)

var (
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
)

var (
// PullCmd command to pull app files
PullCmd = &cobra.Command{
Use: "pull",
Short: "pull",
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

var (
// VersionCmd command to show version info
VersionCmd = &cobra.Command{
Use: "version",
Short: "show version of the bscp-go cli.",
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
)

var (
// WatchCmd command to watch app files
WatchCmd = &cobra.Command{
Use: "watch",
Short: "watch",
Expand Down
2 changes: 1 addition & 1 deletion cli/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package constant

const (
// !important: promise of compatibility
// DefaultTempDir is the bscp cli default temp dir.
// !important: promise of compatibility
DefaultTempDir = "/data/bscp"
)
1 change: 1 addition & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package main

import (
"bscp.io/pkg/logs"

"github.com/TencentBlueKing/bscp-go/cli/cmd"
)

Expand Down
4 changes: 2 additions & 2 deletions cli/util/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ const (
// executePythonCmd python script executor
executePythonCmd = "python3"

// !important: promise of compatibility
// EnvAppTempDir bscp app temp dir env
// !important: promise of compatibility
EnvAppTempDir = "bk_bscp_app_temp_dir"
// EnvTempDir bscp temp dir env
EnvTempDir = "bk_bscp_temp_dir"
// EnvApp bscp biz id env
// EnvBiz bscp biz id env
EnvBiz = "bk_bscp_biz"
// EnvApp bscp app name env
EnvApp = "bk_bscp_app"
Expand Down
4 changes: 2 additions & 2 deletions cli/util/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

"bscp.io/pkg/dal/table"
pbhook "bscp.io/pkg/protocol/core/hook"

"github.com/TencentBlueKing/bscp-go/cli/util"
)

Expand All @@ -42,7 +43,7 @@
Content: hookContent,
}

err = util.ExecuteHook(hookSpec, table.PreHook,tempDir, 2, "bscp-test")
err = util.ExecuteHook(hookSpec, table.PreHook, tempDir, 2, "bscp-test")
if err != nil {
t.Fatalf("execute hook error: %s", err.Error())
}
Expand All @@ -67,7 +68,6 @@
biz := 2
app := "bscp-test"
appTempDir := filepath.Join(tempDir, strconv.Itoa(biz), app)


hookContent := "import os\nos.makedirs('test')"
hookSpec := &pbhook.HookSpec{
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (c *Client) PullFiles(app string, opts ...option.AppOption) (
return resp.ReleaseId, files, resp.PreHook, resp.PostHook, nil
}

func (c *Client) buildVas() (*kit.Vas, context.CancelFunc) {
func (c *Client) buildVas() (*kit.Vas, context.CancelFunc) { // nolint
vas := kit.OutgoingVas(c.pairs)
ctx, cancel := context.WithCancel(vas.Ctx)
vas.Ctx = ctx
Expand Down
11 changes: 7 additions & 4 deletions downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ const (
defaultDownloadSemaphoreWight = 10
)

// DownloadTo defines the download target.
type DownloadTo string

var (
instance *downloader

// DownloadToBytes download file content to bytes.
DownloadToBytes DownloadTo = "bytes"
DownloadToFile DownloadTo = "file"
// DownloadToFile download file content to file.
DownloadToFile DownloadTo = "file"
)

// Downloader implements all the supported operations which used to download
Expand Down Expand Up @@ -213,7 +216,7 @@ func (exec *execDownload) do() error {
exec.downloadUri = resp.Url
if exec.fileSize <= exec.dl.balanceDownloadByteSize {
// the file size is not big enough, download directly
if err := exec.downloadDirectly(requestAwaitResponseTimeoutSeconds); err != nil {
if err = exec.downloadDirectly(requestAwaitResponseTimeoutSeconds); err != nil {
return fmt.Errorf("download directly failed, err: %s", err.Error())
}

Expand Down Expand Up @@ -519,7 +522,7 @@ func tlsConfigFromTLSBytes(tlsBytes *sfs.TLSBytes) (*tls.Config, error) {
var certificate tls.Certificate
if len(tlsBytes.CertFileBytes) == 0 && len(tlsBytes.CertFileBytes) == 0 { //nolint:staticcheck
return &tls.Config{
InsecureSkipVerify: tlsBytes.InsecureSkipVerify,
InsecureSkipVerify: tlsBytes.InsecureSkipVerify, // nolint
ClientCAs: caPool,
Certificates: []tls.Certificate{certificate},
ClientAuth: tls.RequireAndVerifyClientCert,
Expand All @@ -532,7 +535,7 @@ func tlsConfigFromTLSBytes(tlsBytes *sfs.TLSBytes) (*tls.Config, error) {
}

return &tls.Config{
InsecureSkipVerify: tlsBytes.InsecureSkipVerify,
InsecureSkipVerify: tlsBytes.InsecureSkipVerify, // nolint
ClientCAs: caPool,
Certificates: []tls.Certificate{tlsCert},
ClientAuth: tls.RequireAndVerifyClientCert,
Expand Down
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
)

require (
github.com/Tencent/bk-bcs/bcs-common v0.0.0-20230728014611-fe65e97a72fc // indirect
github.com/Tencent/bk-bcs/bcs-common v0.0.0-20230912015319-acb7495967f5 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
Expand All @@ -25,7 +25,7 @@ require (
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -42,7 +42,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tidwall/gjson v1.15.0 // indirect
github.com/tidwall/gjson v1.16.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tjfoc/gmsm v1.4.1 // indirect
Expand All @@ -52,17 +52,17 @@ require (
go.etcd.io/etcd/client/v3 v3.5.9 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
)

replace bscp.io => github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp v0.0.0-20230820092223-29af9a9d259b
replace bscp.io => github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp v0.0.0-20230912072028-e63ab393fd05
Loading
Loading