Skip to content

Commit 2a76e08

Browse files
authored
optimize: optimize golangci lint (#15)
* optimize: optimize golangci lint * optimize: optimize golangci lint * optimize: optimize golangci lint * optimize: optimize golangci lint * optimize: optimize golangci lint * optimize: optimize golangci lint * optimize: optimize golangci lint * fix * fix
1 parent a6f7149 commit 2a76e08

34 files changed

+122
-99
lines changed

.golangci.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# https://golangci-lint.run/usage/configuration#config-file
22

33
linters:
4+
disable:
5+
- typecheck
6+
- gocyclo
7+
48
enable:
59
- staticcheck
610
- unconvert
@@ -11,10 +15,8 @@ linters:
1115
- vet
1216
- unused
1317
- misspell
14-
disable:
15-
- errcheck
1618

1719
run:
1820
deadline: 4m
1921
skip-dirs:
20-
- misc
22+
- ".*/go/pkg/mod/.*"

action/config/config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ package config
22

33
import (
44
"fmt"
5-
"github.com/seata/seata-ctl/model"
6-
"github.com/spf13/cobra"
7-
"gopkg.in/yaml.v3"
85
"log"
96
"os"
7+
8+
"github.com/seata/seata-ctl/model"
9+
"github.com/spf13/cobra"
10+
yaml "gopkg.in/yaml.v3"
1011
)
1112

1213
var Path string
1314

1415
var ConfigCmd = &cobra.Command{
1516
Use: "config",
1617
Short: "Set config path",
17-
Run: func(cmd *cobra.Command, args []string) {
18+
Run: func(_ *cobra.Command, _ []string) {
1819
err := createYMLFile(Path)
1920
if err != nil {
2021
println("Error creating config:", err.Error())

action/get/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func init() {
3434
var ConfigCmd = &cobra.Command{
3535
Use: "config",
3636
Short: "Get the configuration",
37-
Run: func(cmd *cobra.Command, args []string) {
37+
Run: func(_ *cobra.Command, _ []string) {
3838
params, err := common.ParseArrayArg(confKeys)
3939
if err != nil {
4040
common.Log("", err)

action/get/get.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ func init() {
3333
var GetCmd = &cobra.Command{
3434
Use: "get",
3535
Short: "Get the resource",
36-
Run: func(cmd *cobra.Command, args []string) {
37-
cmd.Help()
36+
Run: func(cmd *cobra.Command, _ []string) {
37+
err := cmd.Help()
38+
if err != nil {
39+
return
40+
}
3841
},
3942
}

action/get/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var StatusCmd = &cobra.Command{
2626
Use: "status",
2727
Short: "Get the status",
2828
Long: `Get the status`,
29-
Run: func(cmd *cobra.Command, args []string) {
29+
Run: func(_ *cobra.Command, _ []string) {
3030
seata.GetStatus()
3131
},
3232
}

action/k8s/deploy.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package k8s
33
import (
44
"context"
55
"fmt"
6+
67
"github.com/seata/seata-ctl/action/k8s/utils"
78
"github.com/seata/seata-ctl/tool"
89
"github.com/spf13/cobra"
@@ -14,7 +15,7 @@ import (
1415
var DeployCmd = &cobra.Command{
1516
Use: "deploy",
1617
Short: "deploy seata in k8s",
17-
Run: func(cmd *cobra.Command, args []string) {
18+
Run: func(_ *cobra.Command, _ []string) {
1819
err := deploy()
1920
if err != nil {
2021
tool.Logger.Errorf("deploy err:%v", err)
@@ -43,6 +44,9 @@ func deploy() error {
4344

4445
var seataServer *unstructured.Unstructured
4546
seataServer, err = client.Resource(gvr).Namespace(namespace).Get(context.TODO(), Name, metav1.GetOptions{})
47+
if err != nil {
48+
return err
49+
}
4650
if seataServer != nil {
4751
return fmt.Errorf("seata server already exist! name:" + Name)
4852
}

action/k8s/install.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,20 @@ package k8s
33
import (
44
"context"
55
"fmt"
6+
67
"github.com/seata/seata-ctl/action/k8s/utils"
78
"github.com/seata/seata-ctl/tool"
89
"github.com/spf13/cobra"
9-
_ "gopkg.in/yaml.v3"
10-
_ "io/ioutil"
1110
appsv1 "k8s.io/api/apps/v1"
1211
corev1 "k8s.io/api/core/v1"
13-
_ "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1412
"k8s.io/apimachinery/pkg/api/errors"
15-
_ "k8s.io/apimachinery/pkg/api/errors"
1613
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17-
_ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
18-
_ "k8s.io/apimachinery/pkg/runtime/schema"
19-
_ "k8s.io/client-go/applyconfigurations/meta/v1"
2014
)
2115

2216
var InstallCmd = &cobra.Command{
2317
Use: "install",
2418
Short: "Install Kubernetes CRD controller",
25-
Run: func(cmd *cobra.Command, args []string) {
19+
Run: func(_ *cobra.Command, _ []string) {
2620
err := DeployCRD()
2721
if err != nil {
2822
tool.Logger.Errorf("install CRD err: %v", err)
@@ -65,7 +59,7 @@ func DeployController() error {
6559
_, err = client.AppsV1().Deployments(namespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
6660
if err == nil {
6761
// If the Deployment exists, output a message and return
68-
return fmt.Errorf("Deployment '%s' already exists in the '%s' namespace\n", deploymentName, Namespace)
62+
return fmt.Errorf("deployment '%s' already exists in the '%s' namespace", deploymentName, Namespace)
6963
} else if !errors.IsNotFound(err) {
7064
// If there is an error other than "not found", return it
7165
return fmt.Errorf("error checking for existing deployment: %v", err)

action/k8s/scale.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package k8s
33
import (
44
"context"
55
"fmt"
6+
67
"github.com/seata/seata-ctl/action/k8s/utils"
78
"github.com/seata/seata-ctl/tool"
89
"github.com/spf13/cobra"
@@ -14,7 +15,7 @@ import (
1415
var ScaleCmd = &cobra.Command{
1516
Use: "scale",
1617
Short: "scale seata in k8s",
17-
Run: func(cmd *cobra.Command, args []string) {
18+
Run: func(_ *cobra.Command, _ []string) {
1819
err := scale()
1920
if err != nil {
2021
tool.Logger.Errorf("scale err:%v", err)
@@ -43,6 +44,9 @@ func scale() error {
4344

4445
var seataServer *unstructured.Unstructured
4546
seataServer, err = client.Resource(gvr).Namespace(namespace).Get(context.TODO(), Name, metav1.GetOptions{})
47+
if err != nil {
48+
return err
49+
}
4650
if seataServer == nil {
4751
return fmt.Errorf("This seata server does not exits!" + Name)
4852
}

action/k8s/status.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package k8s
33
import (
44
"context"
55
"fmt"
6+
67
"github.com/seata/seata-ctl/action/k8s/utils"
78
"github.com/seata/seata-ctl/tool"
89
"github.com/spf13/cobra"
@@ -12,7 +13,7 @@ import (
1213
var StatusCmd = &cobra.Command{
1314
Use: "status",
1415
Short: "show seata status in k8s",
15-
Run: func(cmd *cobra.Command, args []string) {
16+
Run: func(_ *cobra.Command, _ []string) {
1617
err := status()
1718
if err != nil {
1819
tool.Logger.Errorf("get k8s status error: %v", err)
@@ -64,7 +65,7 @@ func getPodsStatusByLabel(namespace, labelSelector string) ([]string, error) {
6465

6566
// Build formatted status string for output
6667
statuses = append(statuses, fmt.Sprintf("%-25s %-10s", "POD NAME", "STATUS")) // Header
67-
statuses = append(statuses, fmt.Sprintf("%s", "-------------------------------------------"))
68+
statuses = append(statuses, "-------------------------------------------")
6869

6970
for _, pod := range pods.Items {
7071
statuses = append(statuses, fmt.Sprintf("%-25s %-10s", pod.Name, pod.Status.Phase))

action/k8s/undeploy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package k8s
22

33
import (
44
"context"
5+
56
"github.com/seata/seata-ctl/action/k8s/utils"
67
"github.com/seata/seata-ctl/tool"
78
"github.com/spf13/cobra"
@@ -12,7 +13,7 @@ import (
1213
var UnDeployCmd = &cobra.Command{
1314
Use: "undeploy",
1415
Short: "undeploy seata in k8s",
15-
Run: func(cmd *cobra.Command, args []string) {
16+
Run: func(_ *cobra.Command, _ []string) {
1617
err := undeploy()
1718
if err != nil {
1819
tool.Logger.Errorf("undeploy error: %v", err)

0 commit comments

Comments
 (0)