You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ba...@apache.org on 2025/01/22 06:40:51 UTC

(dubbo-go-pixiu) branch develop updated: ci: actions changed golangci lint (#650)

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

baerwang pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu.git


The following commit(s) were added to refs/heads/develop by this push:
     new e77c3aaf ci: actions changed golangci lint (#650)
e77c3aaf is described below

commit e77c3aaf21b9454b2991b9032f593fb888d60b66
Author: baerwang <ba...@apache.org>
AuthorDate: Wed Jan 22 14:40:40 2025 +0800

    ci: actions changed golangci lint (#650)
---
 .github/actions/review-dog                         |  1 -
 .github/workflows/reviewdog.yml                    |  7 +++--
 configcenter/load.go                               |  4 +--
 .../zookeeper/application_service_listener.go      | 23 ++++++++-------
 .../dubboregistry/remoting/zookeeper/client.go     | 14 +++++----
 pkg/cmd/gateway.go                                 |  4 +--
 pkg/common/grpc/manager.go                         |  5 +++-
 pkg/config/api_config.go                           |  1 +
 pkg/config/config_load.go                          | 33 +++++++++++++---------
 pkg/config/config_load_test.go                     |  5 +---
 pkg/filter/accesslog/access_log.go                 |  1 +
 pkg/filter/http/grpcproxy/descriptor.go            | 18 ++++++------
 pkg/listener/http/http_listener.go                 |  6 ++--
 pkg/router/route.go                                |  8 ++++--
 pkg/server/cluster_manager.go                      |  2 +-
 15 files changed, 71 insertions(+), 61 deletions(-)

diff --git a/.github/actions/review-dog b/.github/actions/review-dog
deleted file mode 160000
index c9fac889..00000000
--- a/.github/actions/review-dog
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit c9fac889cce0d374dc2700eb2bd28987d443fdf9
diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml
index 89feb786..b054929d 100644
--- a/.github/workflows/reviewdog.yml
+++ b/.github/workflows/reviewdog.yml
@@ -17,7 +17,7 @@
 # under the License.
 #
 name: reviewdog
-on: [pull_request]
+on: [ pull_request ]
 jobs:
   golangci-lint:
     name: review
@@ -28,7 +28,8 @@ jobs:
         with:
           persist-credentials: false
           submodules: true
+
       - name: golangci-lint
-        uses: ./.github/actions/review-dog
+        uses: golangci/golangci-lint-action@v6
         with:
-          golangci_lint_flags: "--timeout=10m"
\ No newline at end of file
+          args: --timeout=10m
\ No newline at end of file
diff --git a/configcenter/load.go b/configcenter/load.go
index f16289c3..215cff32 100644
--- a/configcenter/load.go
+++ b/configcenter/load.go
@@ -51,8 +51,8 @@ type (
 		Remote bool
 		DataId string
 		Group  string
-		path   string
-		parser string
+		path   string // nolint:unused
+		parser string // nolint:unused
 	}
 )
 
diff --git a/pkg/adapter/dubboregistry/registry/zookeeper/application_service_listener.go b/pkg/adapter/dubboregistry/registry/zookeeper/application_service_listener.go
index 8ae17827..7f9cfb52 100644
--- a/pkg/adapter/dubboregistry/registry/zookeeper/application_service_listener.go
+++ b/pkg/adapter/dubboregistry/registry/zookeeper/application_service_listener.go
@@ -87,8 +87,10 @@ func (asl *applicationServiceListener) WatchAndHandle() {
 				return
 			}
 			if failTimes > MaxFailTimes {
-				logger.Errorf("Error happens on (path{%s}) exceed max fail times: %v,so exit listen",
-					asl.servicePath, MaxFailTimes)
+				logger.Errorf(
+					"Error happens on (path{%s}) exceed max fail times: %v,so exit listen",
+					asl.servicePath, MaxFailTimes,
+				)
 				return
 			}
 			delayTimer.Reset(ConnDelay * time.Duration(failTimes))
@@ -113,8 +115,10 @@ func (asl *applicationServiceListener) waitEventAndHandlePeriod(children []strin
 		case <-ticker.C:
 			asl.handleEvent(children)
 		case zkEvent := <-e:
-			logger.Warnf("get a zookeeper e{type:%s, server:%s, path:%s, state:%d-%s, err:%s}",
-				zkEvent.Type.String(), zkEvent.Server, zkEvent.Path, zkEvent.State, zookeeper.StateToString(zkEvent.State), zkEvent.Err)
+			logger.Warnf(
+				"get a zookeeper e{type:%s, server:%s, path:%s, state:%d-%s, err:%s}",
+				zkEvent.Type.String(), zkEvent.Server, zkEvent.Path, zkEvent.State, zookeeper.StateToString(zkEvent.State), zkEvent.Err,
+			)
 			if zkEvent.Type != zk.EventNodeChildrenChanged {
 				return true
 			}
@@ -169,7 +173,7 @@ func (asl *applicationServiceListener) handleEvent(children []string) {
 				MapTo: "opt.types",
 			},
 		}
-		if methods != nil && len(methods) != 0 {
+		if len(methods) != 0 {
 			for i := range methods {
 				api := registry.CreateAPIConfig(apiPattern, location, bkConfig, methods[i], mappingParams)
 				if err := asl.adapterListener.OnAddAPI(api); err != nil {
@@ -211,7 +215,7 @@ func (asl *applicationServiceListener) getUrls(path string) []*dubboCommon.URL {
 		return nil
 	}
 	instance.SetServiceMetadata(metadataInfo)
-	urls := make([]*dubboCommon.URL, 0)
+	urls := make([]*dubboCommon.URL, 0, len(metadataInfo.Services))
 	for _, service := range metadataInfo.Services {
 		urls = append(urls, instance.ToURLs(service)...)
 	}
@@ -247,8 +251,6 @@ func toZookeeperInstance(cris *curator_discovery.ServiceInstance) dr.ServiceInst
 
 // getMethods return the methods of a service
 func (asl *applicationServiceListener) getMethods(in string) ([]string, error) {
-	methods := []string{}
-
 	path := strings.Join([]string{methodsRootPath, in}, constant.PathSlash)
 	data, err := asl.client.GetContent(path)
 	if err != nil {
@@ -261,8 +263,9 @@ func (asl *applicationServiceListener) getMethods(in string) ([]string, error) {
 		return nil, err
 	}
 
-	for _, m := range sd.Methods {
-		methods = append(methods, m.Name)
+	methods := make([]string, len(sd.Methods))
+	for i := range sd.Methods {
+		methods[i] = sd.Methods[i].Name
 	}
 	return methods, nil
 }
diff --git a/pkg/adapter/dubboregistry/remoting/zookeeper/client.go b/pkg/adapter/dubboregistry/remoting/zookeeper/client.go
index d616b08d..aafc7456 100644
--- a/pkg/adapter/dubboregistry/remoting/zookeeper/client.go
+++ b/pkg/adapter/dubboregistry/remoting/zookeeper/client.go
@@ -44,7 +44,7 @@ var (
 // Options defines the client option.
 type Options struct {
 	zkName string
-	ts     *zk.TestCluster
+	ts     *zk.TestCluster // nolint:unused
 }
 
 // Option defines the function to load the options
@@ -158,8 +158,10 @@ func (z *ZooKeeperClient) HandleZkEvent(s <-chan zk.Event) {
 		case <-z.exit:
 			return
 		case event = <-s:
-			logger.Infof("client{%s} get a zookeeper event{type:%s, server:%s, path:%s, state:%d-%s, err:%v}",
-				z.name, event.Type, event.Server, event.Path, event.State, StateToString(event.State), event.Err)
+			logger.Infof(
+				"client{%s} get a zookeeper event{type:%s, server:%s, path:%s, state:%d-%s, err:%v}",
+				z.name, event.Type, event.Server, event.Path, event.State, StateToString(event.State), event.Err,
+			)
 			switch event.State {
 			case zk.StateDisconnected:
 				logger.Warnf("zk{addr:%s} state is StateDisconnected, so close the zk client{name:%s}.", z.ZkAddrs, z.name)
@@ -170,8 +172,10 @@ func (z *ZooKeeperClient) HandleZkEvent(s <-chan zk.Event) {
 				z.eventRegistryLock.RLock()
 				for path, a := range z.eventRegistry {
 					if strings.HasPrefix(event.Path, path) {
-						logger.Infof("send event{state:zk.EventNodeDataChange, Path:%s} notify event to path{%s} related listener",
-							event.Path, path)
+						logger.Infof(
+							"send event{state:zk.EventNodeDataChange, Path:%s} notify event to path{%s} related listener",
+							event.Path, path,
+						)
 						for _, e := range a {
 							e <- event
 						}
diff --git a/pkg/cmd/gateway.go b/pkg/cmd/gateway.go
index 4392d29b..96bb4ae5 100644
--- a/pkg/cmd/gateway.go
+++ b/pkg/cmd/gateway.go
@@ -57,9 +57,6 @@ var (
 	logFormat string
 
 	limitCpus string
-
-	// Currently default set to false, wait for up coming support
-	initFromRemote = false
 )
 
 var (
@@ -191,6 +188,7 @@ func initLogWithConfig(boot *model.Bootstrap) {
 	}
 }
 
+// nolint
 // initApiConfig return value of the bool is for the judgment of whether is a api meta data error, a kind of silly (?)
 func initApiConfig() (*model.Bootstrap, error) {
 	bootstrap := config.Load(configPath)
diff --git a/pkg/common/grpc/manager.go b/pkg/common/grpc/manager.go
index 73294661..a06b3f48 100644
--- a/pkg/common/grpc/manager.go
+++ b/pkg/common/grpc/manager.go
@@ -131,7 +131,10 @@ func (gcm *GrpcConnectionManager) response(w stdHttp.ResponseWriter, res *stdHtt
 	if err != nil {
 		return err
 	}
-	w.Write(bytes)
+
+	if _, err = w.Write(bytes); err != nil {
+		return err
+	}
 
 	for k, vv := range res.Trailer {
 		k = stdHttp.TrailerPrefix + k
diff --git a/pkg/config/api_config.go b/pkg/config/api_config.go
index 11bb1427..55642e89 100644
--- a/pkg/config/api_config.go
+++ b/pkg/config/api_config.go
@@ -454,6 +454,7 @@ func getExtractMethodRegexp() *regexp.Regexp {
 	return regexp.MustCompile(".+/resources/([^/]+)/method/[^/]+/?$")
 }
 
+// nolint
 func getCheckRatelimitRegexp() *regexp.Regexp {
 	return regexp.MustCompile(".+/filter/ratelimit")
 }
diff --git a/pkg/config/config_load.go b/pkg/config/config_load.go
index 25fcae13..af3653ec 100644
--- a/pkg/config/config_load.go
+++ b/pkg/config/config_load.go
@@ -44,8 +44,7 @@ var (
 	config         *model.Bootstrap
 	configLoadFunc LoadFunc = LoadYAMLConfig
 
-	configCenterType map[string]interface{}
-	once             sync.Once
+	once sync.Once
 )
 
 // LoadFunc ConfigLoadFunc parse a input(usually file path) into a pixiu config
@@ -182,7 +181,7 @@ func GetDiscoveryType(cfg *model.Bootstrap) (err error) {
 }
 
 type ConfigManager struct {
-	path         string
+	path         string // nolint:unused
 	localConfig  *model.Bootstrap
 	remoteConfig *model.Bootstrap
 	load         configcenter.Load
@@ -227,22 +226,28 @@ func (m *ConfigManager) loadRemoteBootConfigs() *model.Bootstrap {
 	bootstrap := m.localConfig
 
 	// load remote
-	once.Do(func() {
-		m.load = configcenter.NewConfigLoad(bootstrap)
-	})
-
-	configs, err := m.load.LoadConfigs(bootstrap, func(opt *configcenter.Options) {
-		opt.Remote = true
-	})
+	once.Do(
+		func() {
+			m.load = configcenter.NewConfigLoad(bootstrap)
+		},
+	)
+
+	configs, err := m.load.LoadConfigs(
+		bootstrap, func(opt *configcenter.Options) {
+			opt.Remote = true
+		},
+	)
 
 	if err != nil {
 		panic(err)
 	}
 
-	err = mergo.Merge(configs, bootstrap, func(c *mergo.Config) {
-		c.Overwrite = false
-		c.AppendSlice = false
-	})
+	err = mergo.Merge(
+		configs, bootstrap, func(c *mergo.Config) {
+			c.Overwrite = false
+			c.AppendSlice = false
+		},
+	)
 
 	if err != nil {
 		panic(err)
diff --git a/pkg/config/config_load_test.go b/pkg/config/config_load_test.go
index 68c2720e..e3ce5ec8 100644
--- a/pkg/config/config_load_test.go
+++ b/pkg/config/config_load_test.go
@@ -19,7 +19,6 @@ package config
 
 import (
 	"encoding/json"
-	"fmt"
 	"log"
 	"os"
 	"testing"
@@ -140,11 +139,9 @@ func TestLoad(t *testing.T) {
 	conf := Load("conf_test.yaml")
 	assert.Equal(t, 1, len(conf.StaticResources.Listeners))
 	assert.Equal(t, 1, len(conf.StaticResources.Clusters))
-	Adapter(&b)
+	assert.Nil(t, Adapter(&b))
 	str1, _ := json.Marshal(conf.StaticResources)
 	str2, _ := json.Marshal(b.StaticResources)
-	fmt.Println(string(str1))
-	fmt.Println(string(str2))
 	assert.Equal(t, string(str1), string(str2))
 }
 
diff --git a/pkg/filter/accesslog/access_log.go b/pkg/filter/accesslog/access_log.go
index b475bf69..5cc1bedb 100644
--- a/pkg/filter/accesslog/access_log.go
+++ b/pkg/filter/accesslog/access_log.go
@@ -149,6 +149,7 @@ func buildAccessLogMsg(c *http.HttpContext, cost time.Duration) string {
 	return builder.String()
 }
 
+// nolint
 // converter interface to byte array
 func getBytes(key interface{}) ([]byte, error) {
 	var buf bytes.Buffer
diff --git a/pkg/filter/http/grpcproxy/descriptor.go b/pkg/filter/http/grpcproxy/descriptor.go
index a4d996f4..fed66b29 100644
--- a/pkg/filter/http/grpcproxy/descriptor.go
+++ b/pkg/filter/http/grpcproxy/descriptor.go
@@ -103,12 +103,13 @@ func (dr *Descriptor) initDescriptorSource(cfg *Config) *Descriptor {
 }
 
 func (dr *Descriptor) getServerDescriptorSourceCtx(refCtx context.Context, cfg *Config) (DescriptorSource, error) {
-	var cc *grpc.ClientConn
-	var err error
-	gconn := refCtx.Value(ct.ContextKey(GrpcClientConnKey))
-	switch t := gconn.(type) {
+	var (
+		err error
+		cc  *grpc.ClientConn
+	)
+	switch t := refCtx.Value(ct.ContextKey(GrpcClientConnKey)).(type) {
 	case *grpc.ClientConn:
-		cc = gconn.(*grpc.ClientConn)
+		cc = t
 	case nil:
 		err = errors.New("the descriptor source not found!")
 	default:
@@ -117,19 +118,16 @@ func (dr *Descriptor) getServerDescriptorSourceCtx(refCtx context.Context, cfg *
 	return &serverSource{client: grpcreflect.NewClient(refCtx, reflectpb.NewServerReflectionClient(cc))}, err
 }
 
+// nolint
 func (dr *Descriptor) getServerDescriptorSource(refCtx context.Context, cc *grpc.ClientConn) DescriptorSource {
 	return &serverSource{client: grpcreflect.NewClient(refCtx, reflectpb.NewServerReflectionClient(cc))}
 }
 
 func (dr *Descriptor) getFileDescriptorCompose(ctx context.Context, cfg *Config) (DescriptorSource, error) {
-
-	var err error
-
 	if dr.fileSource == nil {
 		dr.initFileDescriptorSource(cfg)
 	}
-
-	return dr.fileSource, err
+	return dr.fileSource, nil
 }
 
 func (dr *Descriptor) initFileDescriptorSource(cfg *Config) *Descriptor {
diff --git a/pkg/listener/http/http_listener.go b/pkg/listener/http/http_listener.go
index 9ed2015a..6af98cb9 100644
--- a/pkg/listener/http/http_listener.go
+++ b/pkg/listener/http/http_listener.go
@@ -110,8 +110,7 @@ func (ls *HttpListenerService) httpsListener() {
 	hl := createDefaultHttpWorker(ls)
 
 	// user customize http config
-	var hc *model.HttpConfig
-	hc = model.MapInStruct(ls.Config)
+	hc := model.MapInStruct(ls.Config)
 
 	mux := http.NewServeMux()
 	mux.HandleFunc("/", hl.ServeHTTP)
@@ -139,8 +138,7 @@ func (ls *HttpListenerService) httpListener() {
 	hl := createDefaultHttpWorker(ls)
 
 	// user customize http config
-	var hc *model.HttpConfig
-	hc = model.MapInStruct(ls.Config)
+	hc := model.MapInStruct(ls.Config)
 
 	mux := http.NewServeMux()
 	mux.HandleFunc("/", hl.ServeHTTP)
diff --git a/pkg/router/route.go b/pkg/router/route.go
index f21e5be2..6112bff8 100644
--- a/pkg/router/route.go
+++ b/pkg/router/route.go
@@ -39,7 +39,7 @@ import (
 // Node defines the single method of the router configured API
 type Node struct {
 	fullPath string
-	filters  []string
+	filters  []string // nolint:unused
 	method   *config.Method
 	headers  map[string]string
 }
@@ -134,8 +134,10 @@ func (rt *Route) PutAPI(api router.API) error {
 		_, _ = rt.tree.Put(key, rn)
 		return nil
 	}
-	return errors.Errorf("Method %s with address %s already exists in path %s",
-		api.Method.HTTPVerb, lowerCasePath, node.fullPath)
+	return errors.Errorf(
+		"Method %s with address %s already exists in path %s",
+		api.Method.HTTPVerb, lowerCasePath, node.fullPath,
+	)
 }
 
 // PutOrUpdateAPI puts or updates an api into the resource
diff --git a/pkg/server/cluster_manager.go b/pkg/server/cluster_manager.go
index f46a6ca1..8e33046f 100644
--- a/pkg/server/cluster_manager.go
+++ b/pkg/server/cluster_manager.go
@@ -162,7 +162,7 @@ func (cm *ClusterManager) PickEndpoint(clusterName string, policy model.LbPolicy
 }
 
 func (cm *ClusterManager) pickOneEndpoint(c *model.ClusterConfig, policy model.LbPolicy) *model.Endpoint {
-	if c.Endpoints == nil || len(c.Endpoints) == 0 {
+	if len(c.Endpoints) == 0 {
 		return nil
 	}