You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by xj...@apache.org on 2025/06/03 13:00:41 UTC

(incubator-seata-ctl) branch main updated: optimize: optimize golangci lint (#15)

This is an automated email from the ASF dual-hosted git repository.

xjlgod pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-seata-ctl.git


The following commit(s) were added to refs/heads/main by this push:
     new 2a76e08  optimize: optimize golangci lint (#15)
2a76e08 is described below

commit 2a76e0857e2a9bbce8384ca883111f74401b8e8d
Author: jimin <sl...@163.com>
AuthorDate: Tue Jun 3 21:00:38 2025 +0800

    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
---
 .golangci.yml                          |  8 +++++---
 action/config/config.go                |  9 +++++----
 action/get/config.go                   |  2 +-
 action/get/get.go                      |  7 +++++--
 action/get/status.go                   |  2 +-
 action/k8s/deploy.go                   |  6 +++++-
 action/k8s/install.go                  | 12 +++---------
 action/k8s/scale.go                    |  6 +++++-
 action/k8s/status.go                   |  5 +++--
 action/k8s/undeploy.go                 |  3 ++-
 action/k8s/uninstall.go                |  3 ++-
 action/k8s/utils/file.go               |  5 +++--
 action/k8s/utils/http.go               | 26 +++++++++++++-------------
 action/k8s/utils/yaml.go               |  6 +++---
 action/log/log.go                      |  7 ++++---
 action/log/logadapter/elasticsearch.go | 14 ++++++--------
 action/log/logadapter/local.go         |  8 ++++----
 action/log/logadapter/loki.go          |  6 +++---
 action/login/login.go                  | 30 +++++++++++++++++++++---------
 action/prometheus/metrics.go           | 22 +++++++++++-----------
 action/quit.go                         |  2 +-
 action/reload/reload.go                |  2 +-
 action/root.go                         |  2 +-
 action/set/config.go                   |  2 +-
 action/set/set.go                      |  2 +-
 action/try/begin.go                    |  2 +-
 action/try/commit.go                   |  2 +-
 action/try/rollback.go                 |  2 +-
 action/try/try.go                      |  2 +-
 cmd/root.go                            |  7 ++++---
 cmd/version.go                         |  2 +-
 go.mod                                 |  2 +-
 go.sum                                 |  2 --
 tool/log.go                            |  3 ++-
 34 files changed, 122 insertions(+), 99 deletions(-)

diff --git a/.golangci.yml b/.golangci.yml
index 90cef62..aa343c7 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -1,6 +1,10 @@
 # https://golangci-lint.run/usage/configuration#config-file
 
 linters:
+  disable:
+    - typecheck
+    - gocyclo
+
   enable:
     - staticcheck
     - unconvert
@@ -11,10 +15,8 @@ linters:
     - vet
     - unused
     - misspell
-  disable:
-    - errcheck
 
 run:
   deadline: 4m
   skip-dirs:
-    - misc
\ No newline at end of file
+    - ".*/go/pkg/mod/.*"
\ No newline at end of file
diff --git a/action/config/config.go b/action/config/config.go
index ddfa5e3..1878a32 100644
--- a/action/config/config.go
+++ b/action/config/config.go
@@ -2,11 +2,12 @@ package config
 
 import (
 	"fmt"
-	"github.com/seata/seata-ctl/model"
-	"github.com/spf13/cobra"
-	"gopkg.in/yaml.v3"
 	"log"
 	"os"
+
+	"github.com/seata/seata-ctl/model"
+	"github.com/spf13/cobra"
+	yaml "gopkg.in/yaml.v3"
 )
 
 var Path string
@@ -14,7 +15,7 @@ var Path string
 var ConfigCmd = &cobra.Command{
 	Use:   "config",
 	Short: "Set config path",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		err := createYMLFile(Path)
 		if err != nil {
 			println("Error creating config:", err.Error())
diff --git a/action/get/config.go b/action/get/config.go
index 9c7e28a..d154d50 100644
--- a/action/get/config.go
+++ b/action/get/config.go
@@ -34,7 +34,7 @@ func init() {
 var ConfigCmd = &cobra.Command{
 	Use:   "config",
 	Short: "Get the configuration",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		params, err := common.ParseArrayArg(confKeys)
 		if err != nil {
 			common.Log("", err)
diff --git a/action/get/get.go b/action/get/get.go
index e9033f3..80d2480 100644
--- a/action/get/get.go
+++ b/action/get/get.go
@@ -33,7 +33,10 @@ func init() {
 var GetCmd = &cobra.Command{
 	Use:   "get",
 	Short: "Get the resource",
-	Run: func(cmd *cobra.Command, args []string) {
-		cmd.Help()
+	Run: func(cmd *cobra.Command, _ []string) {
+		err := cmd.Help()
+		if err != nil {
+			return
+		}
 	},
 }
diff --git a/action/get/status.go b/action/get/status.go
index 890900a..78b5446 100644
--- a/action/get/status.go
+++ b/action/get/status.go
@@ -26,7 +26,7 @@ var StatusCmd = &cobra.Command{
 	Use:   "status",
 	Short: "Get the status",
 	Long:  `Get the status`,
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		seata.GetStatus()
 	},
 }
diff --git a/action/k8s/deploy.go b/action/k8s/deploy.go
index 3499a32..9831ad4 100644
--- a/action/k8s/deploy.go
+++ b/action/k8s/deploy.go
@@ -3,6 +3,7 @@ package k8s
 import (
 	"context"
 	"fmt"
+
 	"github.com/seata/seata-ctl/action/k8s/utils"
 	"github.com/seata/seata-ctl/tool"
 	"github.com/spf13/cobra"
@@ -14,7 +15,7 @@ import (
 var DeployCmd = &cobra.Command{
 	Use:   "deploy",
 	Short: "deploy seata in k8s",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		err := deploy()
 		if err != nil {
 			tool.Logger.Errorf("deploy err:%v", err)
@@ -43,6 +44,9 @@ func deploy() error {
 
 	var seataServer *unstructured.Unstructured
 	seataServer, err = client.Resource(gvr).Namespace(namespace).Get(context.TODO(), Name, metav1.GetOptions{})
+	if err != nil {
+		return err
+	}
 	if seataServer != nil {
 		return fmt.Errorf("seata server already exist! name:" + Name)
 	}
diff --git a/action/k8s/install.go b/action/k8s/install.go
index 3434b2c..fae3fb5 100644
--- a/action/k8s/install.go
+++ b/action/k8s/install.go
@@ -3,26 +3,20 @@ package k8s
 import (
 	"context"
 	"fmt"
+
 	"github.com/seata/seata-ctl/action/k8s/utils"
 	"github.com/seata/seata-ctl/tool"
 	"github.com/spf13/cobra"
-	_ "gopkg.in/yaml.v3"
-	_ "io/ioutil"
 	appsv1 "k8s.io/api/apps/v1"
 	corev1 "k8s.io/api/core/v1"
-	_ "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
 	"k8s.io/apimachinery/pkg/api/errors"
-	_ "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-	_ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
-	_ "k8s.io/apimachinery/pkg/runtime/schema"
-	_ "k8s.io/client-go/applyconfigurations/meta/v1"
 )
 
 var InstallCmd = &cobra.Command{
 	Use:   "install",
 	Short: "Install Kubernetes CRD controller",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		err := DeployCRD()
 		if err != nil {
 			tool.Logger.Errorf("install CRD err: %v", err)
@@ -65,7 +59,7 @@ func DeployController() error {
 	_, err = client.AppsV1().Deployments(namespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
 	if err == nil {
 		// If the Deployment exists, output a message and return
-		return fmt.Errorf("Deployment '%s' already exists in the '%s' namespace\n", deploymentName, Namespace)
+		return fmt.Errorf("deployment '%s' already exists in the '%s' namespace", deploymentName, Namespace)
 	} else if !errors.IsNotFound(err) {
 		// If there is an error other than "not found", return it
 		return fmt.Errorf("error checking for existing deployment: %v", err)
diff --git a/action/k8s/scale.go b/action/k8s/scale.go
index 1b091c3..79da344 100644
--- a/action/k8s/scale.go
+++ b/action/k8s/scale.go
@@ -3,6 +3,7 @@ package k8s
 import (
 	"context"
 	"fmt"
+
 	"github.com/seata/seata-ctl/action/k8s/utils"
 	"github.com/seata/seata-ctl/tool"
 	"github.com/spf13/cobra"
@@ -14,7 +15,7 @@ import (
 var ScaleCmd = &cobra.Command{
 	Use:   "scale",
 	Short: "scale seata in k8s",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		err := scale()
 		if err != nil {
 			tool.Logger.Errorf("scale err:%v", err)
@@ -43,6 +44,9 @@ func scale() error {
 
 	var seataServer *unstructured.Unstructured
 	seataServer, err = client.Resource(gvr).Namespace(namespace).Get(context.TODO(), Name, metav1.GetOptions{})
+	if err != nil {
+		return err
+	}
 	if seataServer == nil {
 		return fmt.Errorf("This seata server does not exits!" + Name)
 	}
diff --git a/action/k8s/status.go b/action/k8s/status.go
index 72bfc49..77a23fb 100644
--- a/action/k8s/status.go
+++ b/action/k8s/status.go
@@ -3,6 +3,7 @@ package k8s
 import (
 	"context"
 	"fmt"
+
 	"github.com/seata/seata-ctl/action/k8s/utils"
 	"github.com/seata/seata-ctl/tool"
 	"github.com/spf13/cobra"
@@ -12,7 +13,7 @@ import (
 var StatusCmd = &cobra.Command{
 	Use:   "status",
 	Short: "show seata status in k8s",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		err := status()
 		if err != nil {
 			tool.Logger.Errorf("get k8s status error: %v", err)
@@ -64,7 +65,7 @@ func getPodsStatusByLabel(namespace, labelSelector string) ([]string, error) {
 
 	// Build formatted status string for output
 	statuses = append(statuses, fmt.Sprintf("%-25s %-10s", "POD NAME", "STATUS")) // Header
-	statuses = append(statuses, fmt.Sprintf("%s", "-------------------------------------------"))
+	statuses = append(statuses, "-------------------------------------------")
 
 	for _, pod := range pods.Items {
 		statuses = append(statuses, fmt.Sprintf("%-25s %-10s", pod.Name, pod.Status.Phase))
diff --git a/action/k8s/undeploy.go b/action/k8s/undeploy.go
index 90bb84d..9b65ef0 100644
--- a/action/k8s/undeploy.go
+++ b/action/k8s/undeploy.go
@@ -2,6 +2,7 @@ package k8s
 
 import (
 	"context"
+
 	"github.com/seata/seata-ctl/action/k8s/utils"
 	"github.com/seata/seata-ctl/tool"
 	"github.com/spf13/cobra"
@@ -12,7 +13,7 @@ import (
 var UnDeployCmd = &cobra.Command{
 	Use:   "undeploy",
 	Short: "undeploy seata in k8s",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		err := undeploy()
 		if err != nil {
 			tool.Logger.Errorf("undeploy error: %v", err)
diff --git a/action/k8s/uninstall.go b/action/k8s/uninstall.go
index 3a683f0..6fccd15 100644
--- a/action/k8s/uninstall.go
+++ b/action/k8s/uninstall.go
@@ -2,6 +2,7 @@ package k8s
 
 import (
 	"context"
+
 	"github.com/seata/seata-ctl/action/k8s/utils"
 	"github.com/seata/seata-ctl/tool"
 	"github.com/spf13/cobra"
@@ -13,7 +14,7 @@ import (
 var UnInstallCmd = &cobra.Command{
 	Use:   "uninstall",
 	Short: "uninstall seata in k8s",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		err := UninstallCRD()
 		if err != nil {
 			tool.Logger.Errorf("uninstall CRD err:%v", err)
diff --git a/action/k8s/utils/file.go b/action/k8s/utils/file.go
index e4968b1..db20892 100644
--- a/action/k8s/utils/file.go
+++ b/action/k8s/utils/file.go
@@ -2,12 +2,13 @@ package utils
 
 import (
 	"fmt"
+	"os"
+
 	"github.com/seata/seata-ctl/model"
-	"gopkg.in/yaml.v3"
+	yaml "gopkg.in/yaml.v3"
 	"k8s.io/client-go/dynamic"
 	"k8s.io/client-go/kubernetes"
 	"k8s.io/client-go/tools/clientcmd"
-	"os"
 )
 
 const ConfigFileName = "config.yml"
diff --git a/action/k8s/utils/http.go b/action/k8s/utils/http.go
index e06ade3..ec37c27 100644
--- a/action/k8s/utils/http.go
+++ b/action/k8s/utils/http.go
@@ -5,19 +5,20 @@ import (
 	"crypto/tls"
 	"crypto/x509"
 	"fmt"
-	"github.com/seata/seata-ctl/tool"
 	"io"
-	"io/ioutil"
-	"k8s.io/client-go/tools/clientcmd"
-	"k8s.io/client-go/tools/clientcmd/api"
 	"net/http"
+	"os"
 	"strings"
+
+	"github.com/seata/seata-ctl/tool"
+	"k8s.io/client-go/tools/clientcmd"
+	"k8s.io/client-go/tools/clientcmd/api"
 )
 
 type ContextType string
 
 const (
-	Json ContextType = "application/json"
+	JSON ContextType = "application/json"
 )
 
 // ContextInfo is a structure to hold client certificate, key, CA certificate, API server URL, and content type.
@@ -32,7 +33,7 @@ type ContextInfo struct {
 // LoadKubeConfig loads the kubeconfig from the provided path and filename
 func LoadKubeConfig(kubeconfigFullPath string) (*api.Config, error) {
 	// Read the kubeconfig file
-	kubeconfigBytes, err := ioutil.ReadFile(kubeconfigFullPath)
+	kubeconfigBytes, err := os.ReadFile(kubeconfigFullPath)
 	if err != nil {
 		return nil, fmt.Errorf("failed to read kubeconfig file: %v", err)
 	}
@@ -73,7 +74,7 @@ func GetContextInfo(config *api.Config) (*ContextInfo, error) {
 	caCert := cluster.CertificateAuthority
 	apiServer := cluster.Server
 	// Content type for API request
-	contentType := Json
+	contentType := JSON
 	// Check if all required fields are present
 	if clientCert == "" || clientKey == "" || caCert == "" || apiServer == "" {
 		missingFields := []string{}
@@ -116,7 +117,7 @@ func sendPostRequest(context *ContextInfo, createCrdPath string, filePath string
 	}
 
 	// Read CA certificate
-	caCert, err := ioutil.ReadFile(caCertFile)
+	caCert, err := os.ReadFile(caCertFile)
 	if err != nil {
 		return "", fmt.Errorf("failed to read CA certificate: %v", err)
 	}
@@ -133,7 +134,7 @@ func sendPostRequest(context *ContextInfo, createCrdPath string, filePath string
 	client := &http.Client{Transport: transport}
 
 	// Read data from file
-	data, err := ioutil.ReadFile(filePath)
+	data, err := os.ReadFile(filePath)
 	if err != nil {
 		return "", fmt.Errorf("failed to read data file: %v", err)
 	}
@@ -155,12 +156,12 @@ func sendPostRequest(context *ContextInfo, createCrdPath string, filePath string
 	defer func(Body io.ReadCloser) {
 		err := Body.Close()
 		if err != nil {
-			tool.Logger.Error("failed to close response body: %v", err)
+			tool.Logger.Errorf("failed to close response body: %v", err)
 		}
 	}(resp.Body)
 
 	// Read response body
-	body, err := ioutil.ReadAll(resp.Body)
+	body, err := io.ReadAll(resp.Body)
 	if err != nil {
 		return "", fmt.Errorf("failed to read response: %v", err)
 	}
@@ -172,7 +173,6 @@ func sendPostRequest(context *ContextInfo, createCrdPath string, filePath string
 	}
 	if resp.StatusCode == http.StatusConflict {
 		return "", fmt.Errorf("seata crd already exists")
-	} else {
-		return "error: " + string(body), err
 	}
+	return "error: " + string(body), err
 }
diff --git a/action/k8s/utils/yaml.go b/action/k8s/utils/yaml.go
index ace8721..cca1f23 100644
--- a/action/k8s/utils/yaml.go
+++ b/action/k8s/utils/yaml.go
@@ -2,9 +2,9 @@ package utils
 
 import (
 	"fmt"
-	"io/ioutil"
 	"os"
 	"path/filepath"
+
 	"sigs.k8s.io/yaml"
 )
 
@@ -27,7 +27,7 @@ func ConvertAndSaveYamlToJSON(targetName string) (string, error) {
 	}
 
 	// Read the YAML file
-	yamlData, err := ioutil.ReadFile(targetName)
+	yamlData, err := os.ReadFile(targetName)
 	if err != nil {
 		return "", fmt.Errorf("failed to read YAML file: %v", err)
 	}
@@ -39,7 +39,7 @@ func ConvertAndSaveYamlToJSON(targetName string) (string, error) {
 	}
 
 	// Write the converted JSON data to the new file
-	err = ioutil.WriteFile(newFilePath, jsonData, 0644)
+	err = os.WriteFile(newFilePath, jsonData, 0644)
 	if err != nil {
 		return "", fmt.Errorf("failed to write JSON file: %v", err)
 	}
diff --git a/action/log/log.go b/action/log/log.go
index dcb958c..9e38327 100644
--- a/action/log/log.go
+++ b/action/log/log.go
@@ -2,18 +2,19 @@ package log
 
 import (
 	"fmt"
+	"os"
+
 	"github.com/seata/seata-ctl/action/log/logadapter"
 	"github.com/seata/seata-ctl/model"
 	"github.com/seata/seata-ctl/tool"
 	"github.com/spf13/cobra"
-	"gopkg.in/yaml.v3"
-	"os"
+	yaml "gopkg.in/yaml.v3"
 )
 
 var LogCmd = &cobra.Command{
 	Use:   "log",
 	Short: "get seata log",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		err := getLog()
 		if err != nil {
 			tool.Logger.Errorf("get log error: %s", err)
diff --git a/action/log/logadapter/elasticsearch.go b/action/log/logadapter/elasticsearch.go
index 29b1842..54c270b 100644
--- a/action/log/logadapter/elasticsearch.go
+++ b/action/log/logadapter/elasticsearch.go
@@ -5,13 +5,14 @@ import (
 	"crypto/tls"
 	"encoding/json"
 	"fmt"
-	"github.com/elastic/go-elasticsearch/v8"
-	"github.com/elastic/go-elasticsearch/v8/esapi"
-	"github.com/olivere/elastic/v7"
-	"github.com/seata/seata-ctl/tool"
 	"io"
 	"net/http"
 	"strings"
+
+	elasticsearch "github.com/elastic/go-elasticsearch/v8"
+	"github.com/elastic/go-elasticsearch/v8/esapi"
+	elastic "github.com/olivere/elastic/v7"
+	"github.com/seata/seata-ctl/tool"
 )
 
 // QueryLogs is a function that queries specific documents
@@ -250,10 +251,7 @@ func removeKeywordSuffix(input []string) []string {
 	var result []string
 	for _, str := range input {
 		// Check if the string ends with ".keyword"
-		if strings.HasSuffix(str, ".keyword") {
-			// Remove the ".keyword" suffix
-			str = strings.TrimSuffix(str, ".keyword")
-		}
+		str = strings.TrimSuffix(str, ".keyword")
 		result = append(result, str) // Add the processed string to the result slice
 	}
 	return result
diff --git a/action/log/logadapter/local.go b/action/log/logadapter/local.go
index 5a39f56..b9bba5a 100644
--- a/action/log/logadapter/local.go
+++ b/action/log/logadapter/local.go
@@ -3,11 +3,11 @@ package logadapter
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/seata/seata-ctl/tool"
 	"io"
-	"io/ioutil"
 	"net/http"
 	"strings"
+
+	"github.com/seata/seata-ctl/tool"
 )
 
 // QueryLogs sends a request to the /query endpoint and retrieves logs based on the provided filter.
@@ -31,12 +31,12 @@ func (l *Local) QueryLogs(filter map[string]interface{}, currency *Currency, num
 	defer func(Body io.ReadCloser) {
 		err := Body.Close()
 		if err != nil {
-			tool.Logger.Error("failed to close response body: %v", err)
+			tool.Logger.Errorf("failed to close response body: %v", err)
 		}
 	}(resp.Body)
 
 	// Read the response body
-	body, err := ioutil.ReadAll(resp.Body)
+	body, err := io.ReadAll(resp.Body)
 	if err != nil {
 		return fmt.Errorf("failed to read response body: %v", err)
 	}
diff --git a/action/log/logadapter/loki.go b/action/log/logadapter/loki.go
index 99b9385..ad0df27 100644
--- a/action/log/logadapter/loki.go
+++ b/action/log/logadapter/loki.go
@@ -3,14 +3,14 @@ package logadapter
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/seata/seata-ctl/tool"
 	"io"
-	"io/ioutil"
 	"net/http"
 	"net/url"
 	"strconv"
 	"strings"
 	"time"
+
+	"github.com/seata/seata-ctl/tool"
 )
 
 // QueryLogs queries logs from Loki based on the filter and settings provided
@@ -52,7 +52,7 @@ func (l *Loki) QueryLogs(filter map[string]interface{}, currency *Currency, numb
 	}(resp.Body)
 
 	// Read the response body
-	body, err := ioutil.ReadAll(resp.Body)
+	body, err := io.ReadAll(resp.Body)
 	if err != nil {
 		return fmt.Errorf("error reading response from Loki: %v", err)
 	}
diff --git a/action/login/login.go b/action/login/login.go
index 5cf6141..45cd6bc 100644
--- a/action/login/login.go
+++ b/action/login/login.go
@@ -2,10 +2,11 @@ package login
 
 import (
 	"fmt"
+	"os"
+
 	"github.com/seata/seata-ctl/seata"
 	"github.com/spf13/cobra"
 	"github.com/spf13/viper"
-	"os"
 )
 
 var Address string
@@ -14,17 +15,16 @@ var Address string
 var LoginCmd = &cobra.Command{
 	Use:   "login",
 	Short: "Login to Seata server",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		fmt.Println("Attempting to login...")
 		Address = seata.GetAuth().GetAddress()
 		err := seata.GetAuth().Login()
 		if err != nil {
 			fmt.Println("Login failed!")
 			os.Exit(1)
-		} else {
-			fmt.Printf("Login successful to address: %s\n", Address)
-			printPrompt(Address)
 		}
+		fmt.Printf("Login successful to address: %s\n", Address)
+		printPrompt(Address)
 	},
 }
 
@@ -34,10 +34,22 @@ func init() {
 	LoginCmd.PersistentFlags().IntVar(&credential.ServerPort, "port", 7091, "Seata Server Admin Port")
 	LoginCmd.PersistentFlags().StringVar(&credential.Username, "username", "seata", "Username")
 	LoginCmd.PersistentFlags().StringVar(&credential.Password, "password", "seata", "Password")
-	viper.BindPFlag("ip", LoginCmd.PersistentFlags().Lookup("ip"))
-	viper.BindPFlag("port", LoginCmd.PersistentFlags().Lookup("port"))
-	viper.BindPFlag("username", LoginCmd.PersistentFlags().Lookup("username"))
-	viper.BindPFlag("password", LoginCmd.PersistentFlags().Lookup("password"))
+	err := viper.BindPFlag("ip", LoginCmd.PersistentFlags().Lookup("ip"))
+	if err != nil {
+		return
+	}
+	err = viper.BindPFlag("port", LoginCmd.PersistentFlags().Lookup("port"))
+	if err != nil {
+		return
+	}
+	err = viper.BindPFlag("username", LoginCmd.PersistentFlags().Lookup("username"))
+	if err != nil {
+		return
+	}
+	err = viper.BindPFlag("password", LoginCmd.PersistentFlags().Lookup("password"))
+	if err != nil {
+		return
+	}
 }
 
 func printPrompt(address string) {
diff --git a/action/prometheus/metrics.go b/action/prometheus/metrics.go
index 9030cba..3a174e6 100644
--- a/action/prometheus/metrics.go
+++ b/action/prometheus/metrics.go
@@ -3,24 +3,24 @@ package prometheus
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/guptarohit/asciigraph"
-	"github.com/seata/seata-ctl/action/k8s/utils"
-	"github.com/seata/seata-ctl/model"
-	"github.com/seata/seata-ctl/tool"
-	"github.com/spf13/cobra"
-	"gopkg.in/yaml.v3"
 	"io"
-	"io/ioutil"
 	"net/http"
 	"net/url"
 	"os"
 	"strconv"
+
+	"github.com/guptarohit/asciigraph"
+	"github.com/seata/seata-ctl/action/k8s/utils"
+	"github.com/seata/seata-ctl/model"
+	"github.com/seata/seata-ctl/tool"
+	"github.com/spf13/cobra"
+	yaml "gopkg.in/yaml.v3"
 )
 
 var MetricsCmd = &cobra.Command{
 	Use:   "metrics",
 	Short: "Show Prometheus metrics",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		if err := showMetrics(); err != nil {
 			tool.Logger.Errorf("Failed to show metrics: %v", err)
 		}
@@ -106,7 +106,7 @@ func queryPromMetric(prometheusURL, query string) (*PromResponse, error) {
 	}(resp.Body)
 
 	// Read the response body
-	body, err := ioutil.ReadAll(resp.Body)
+	body, err := io.ReadAll(resp.Body)
 	if err != nil {
 		return nil, fmt.Errorf("error reading response body: %w", err)
 	}
@@ -131,9 +131,9 @@ func generateTerminalLineChart(response *PromResponse, metricName string) error
 				value, err := strconv.ParseFloat(valueStr, 64)
 				if err != nil {
 					return fmt.Errorf("error converting value to float: %v", err)
-				} else {
-					yValues = append(yValues, value)
 				}
+				yValues = append(yValues, value)
+
 			} else {
 				return fmt.Errorf("error converting value to float: %v", result.Value[1])
 			}
diff --git a/action/quit.go b/action/quit.go
index bf8a20c..ae385c8 100644
--- a/action/quit.go
+++ b/action/quit.go
@@ -32,7 +32,7 @@ func init() {
 var quitCmd = &cobra.Command{
 	Use:   "quit",
 	Short: "Quit the session",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		println("Quit the session")
 		os.Exit(0)
 	},
diff --git a/action/reload/reload.go b/action/reload/reload.go
index 6205f09..d1b3e83 100644
--- a/action/reload/reload.go
+++ b/action/reload/reload.go
@@ -31,7 +31,7 @@ func init() {
 var ReloadCmd = &cobra.Command{
 	Use:   "reload",
 	Short: "Reload the configuration",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		seata.ReloadConfiguration()
 	},
 }
diff --git a/action/root.go b/action/root.go
index b8949c6..53a7f35 100644
--- a/action/root.go
+++ b/action/root.go
@@ -59,7 +59,7 @@ func init() {
 }
 
 var rootCmd = &cobra.Command{
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		// Do Stuff Here
 	},
 }
diff --git a/action/set/config.go b/action/set/config.go
index 600b249..76dfbaa 100644
--- a/action/set/config.go
+++ b/action/set/config.go
@@ -38,7 +38,7 @@ func init() {
 var ConfigCmd = &cobra.Command{
 	Use:   "config",
 	Short: "Set the configuration",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		data, err := common.ParseDictArg(kvData)
 		if err != nil {
 			common.Log("", err)
diff --git a/action/set/set.go b/action/set/set.go
index 49d369b..207035d 100644
--- a/action/set/set.go
+++ b/action/set/set.go
@@ -31,6 +31,6 @@ func init() {
 var SetCmd = &cobra.Command{
 	Use:   "set",
 	Short: "Set the resource",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 	},
 }
diff --git a/action/try/begin.go b/action/try/begin.go
index c01ef9f..3dccc95 100644
--- a/action/try/begin.go
+++ b/action/try/begin.go
@@ -36,7 +36,7 @@ func init() {
 var BeginCmd = &cobra.Command{
 	Use:   "begin",
 	Short: "begin a txn",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		seata.BeginTxn(timeout)
 		timeout = 3000
 	},
diff --git a/action/try/commit.go b/action/try/commit.go
index 81a0b16..b3b2d4d 100644
--- a/action/try/commit.go
+++ b/action/try/commit.go
@@ -36,7 +36,7 @@ func init() {
 var CommitCmd = &cobra.Command{
 	Use:   "commit",
 	Short: "commit a txn",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		seata.CommitTxn(commitXID)
 		commitXID = ""
 	},
diff --git a/action/try/rollback.go b/action/try/rollback.go
index 4daa19c..82c1be5 100644
--- a/action/try/rollback.go
+++ b/action/try/rollback.go
@@ -36,7 +36,7 @@ func init() {
 var RollbackCmd = &cobra.Command{
 	Use:   "rollback",
 	Short: "rollback a txn",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		seata.RollbackTxn(rollbackXID)
 		rollbackXID = ""
 	},
diff --git a/action/try/try.go b/action/try/try.go
index b42bcd6..7e94006 100644
--- a/action/try/try.go
+++ b/action/try/try.go
@@ -33,6 +33,6 @@ func init() {
 var TryCmd = &cobra.Command{
 	Use:   "try",
 	Short: "Try example transactions",
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 	},
 }
diff --git a/cmd/root.go b/cmd/root.go
index a32bc82..2eb470b 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -19,9 +19,10 @@ package cmd
 
 import (
 	"fmt"
+	"os"
+
 	"github.com/seata/seata-ctl/action/login"
 	"github.com/seata/seata-ctl/tool"
-	"os"
 
 	"github.com/seata/seata-ctl/action"
 	"github.com/seata/seata-ctl/action/common"
@@ -32,7 +33,7 @@ var (
 	rootCmd = &cobra.Command{
 		Use:   "seata-ctl",
 		Short: "seata-ctl is a CLI tool for Seata",
-		Run: func(cmd *cobra.Command, args []string) {
+		Run: func(_ *cobra.Command, _ []string) {
 			// Do Stuff Here
 		},
 	}
@@ -42,7 +43,7 @@ func init() {
 	rootCmd.SetHelpCommand(&cobra.Command{
 		Use:   "seata-ctl",
 		Short: "seata-ctl is a CLI tool for Seata",
-		Run: func(cmd *cobra.Command, args []string) {
+		Run: func(_ *cobra.Command, _ []string) {
 			//
 		},
 	})
diff --git a/cmd/version.go b/cmd/version.go
index 88eb10c..2635477 100644
--- a/cmd/version.go
+++ b/cmd/version.go
@@ -31,7 +31,7 @@ var versionCmd = &cobra.Command{
 	Use:   "version",
 	Short: "Print the version number of seata-ctl",
 	Long:  `All software has versions. This is seata-ctl's`,
-	Run: func(cmd *cobra.Command, args []string) {
+	Run: func(_ *cobra.Command, _ []string) {
 		fmt.Println("v0.0")
 	},
 }
diff --git a/go.mod b/go.mod
index a0001ea..54dcc50 100644
--- a/go.mod
+++ b/go.mod
@@ -13,7 +13,6 @@ require (
 	github.com/stretchr/testify v1.9.0
 	gopkg.in/yaml.v3 v3.0.1
 	k8s.io/api v0.31.2
-	k8s.io/apiextensions-apiserver v0.31.2
 	k8s.io/apimachinery v0.31.2
 	k8s.io/client-go v0.31.2
 	sigs.k8s.io/yaml v1.4.0
@@ -60,6 +59,7 @@ require (
 	github.com/x448/float16 v0.8.4 // indirect
 	go.opentelemetry.io/otel v1.28.0 // indirect
 	go.opentelemetry.io/otel/metric v1.28.0 // indirect
+	go.opentelemetry.io/otel/sdk v1.28.0 // indirect
 	go.opentelemetry.io/otel/trace v1.28.0 // indirect
 	golang.org/x/net v0.26.0 // indirect
 	golang.org/x/oauth2 v0.21.0 // indirect
diff --git a/go.sum b/go.sum
index f2bea78..e8c04dd 100644
--- a/go.sum
+++ b/go.sum
@@ -600,8 +600,6 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
 honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
 k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0=
 k8s.io/api v0.31.2/go.mod h1:bWmGvrGPssSK1ljmLzd3pwCQ9MgoTsRCuK35u6SygUk=
-k8s.io/apiextensions-apiserver v0.31.2 h1:W8EwUb8+WXBLu56ser5IudT2cOho0gAKeTOnywBLxd0=
-k8s.io/apiextensions-apiserver v0.31.2/go.mod h1:i+Geh+nGCJEGiCGR3MlBDkS7koHIIKWVfWeRFiOsUcM=
 k8s.io/apimachinery v0.31.2 h1:i4vUt2hPK56W6mlT7Ry+AO8eEsyxMD1U44NR22CLTYw=
 k8s.io/apimachinery v0.31.2/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
 k8s.io/client-go v0.31.2 h1:Y2F4dxU5d3AQj+ybwSMqQnpZH9F30//1ObxOKlTI9yc=
diff --git a/tool/log.go b/tool/log.go
index d194d65..f44e394 100644
--- a/tool/log.go
+++ b/tool/log.go
@@ -1,8 +1,9 @@
 package tool
 
 import (
-	"github.com/sirupsen/logrus"
 	"sync"
+
+	"github.com/sirupsen/logrus"
 )
 
 // Logger Global logger instance


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org