You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/01/04 09:00:41 UTC

[dubbo-go] branch develop updated (b6022bb -> 9e40791)

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

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


    omit b6022bb  fix ctx linter error
     new 9e40791  fix ctx linter error

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (b6022bb)
            \
             N -- N -- N   refs/heads/develop (9e40791)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .golangci.yml                            | 63 ++++++++++++++++++++++++++++++++
 protocol/dubbo/hessian2/hessian_dubbo.go |  2 +-
 protocol/dubbo/impl/codec.go             |  2 +-
 remoting/getty/listener.go               | 10 ++---
 4 files changed, 70 insertions(+), 7 deletions(-)
 create mode 100644 .golangci.yml


[dubbo-go] 01/01: fix ctx linter error

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9e40791f1c896fe97a1c5ed17877e2f9cdd106de
Author: AlexStocks <al...@foxmail.com>
AuthorDate: Mon Jan 4 15:06:32 2021 +0800

    fix ctx linter error
---
 .golangci.yml                                      | 63 ++++++++++++++++++++++
 common/constant/key.go                             |  2 +-
 common/url.go                                      |  8 +--
 common/url_test.go                                 | 42 +++++++++++----
 config_center/apollo/listener.go                   |  2 +-
 .../tps/tps_limiter_method_service_test.go         |  2 +-
 protocol/dubbo/hessian2/hessian_dubbo.go           |  2 +-
 protocol/dubbo/impl/codec.go                       |  2 +-
 remoting/getty/listener.go                         | 10 ++--
 remoting/getty/listener_test.go                    |  6 +--
 10 files changed, 114 insertions(+), 25 deletions(-)

diff --git a/.golangci.yml b/.golangci.yml
new file mode 100644
index 0000000..6f214f4
--- /dev/null
+++ b/.golangci.yml
@@ -0,0 +1,63 @@
+linters-settings:
+  govet:
+    check-shadowing: true
+  golint:
+    min-confidence: 0
+  gocyclo:
+    min-complexity: 10
+  maligned:
+    suggest-new: true
+  dupl:
+    threshold: 100
+  goconst:
+    min-len: 2
+    min-occurrences: 2
+  depguard:
+    list-type: blacklist
+    packages:
+      # logging is allowed only by logutils.Log, logrus
+      # is allowed to use only in logutils package
+      - github.com/sirupsen/logrus
+  misspell:
+    locale: US
+  lll:
+    line-length: 140
+  goimports:
+    local-prefixes: github.com/golangci/golangci-lint
+  gocritic:
+    enabled-tags:
+      - performance
+      - style
+      - experimental
+    disabled-checks:
+      - wrapperFunc
+
+linters:
+  disable-all: true
+  enable:
+    - govet
+    - staticcheck
+    - ineffassign
+    - misspell
+
+run:
+  skip-dirs:
+    - test/testdata_etc
+    - pkg/golinters/goanalysis/(checker|passes)
+
+issues:
+  exclude-rules:
+    - text: "weak cryptographic primitive"
+      linters:
+        - gosec
+    - linters:
+        - staticcheck
+      text: "SA1019:"
+
+# golangci.com configuration
+# https://github.com/golangci/golangci/wiki/Configuration
+service:
+  golangci-lint-version: 1.15.x # use the fixed version to not introduce new linters unexpectedly
+  prepare:
+    - echo "here I can run custom commands, but no preparation needed for this repo"
+
diff --git a/common/constant/key.go b/common/constant/key.go
index 12e3096..50aea81 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -200,7 +200,7 @@ const (
 )
 
 const (
-	TRACING_REMOTE_SPAN_CTX = "tracing.remote.span.ctx"
+	TRACING_REMOTE_SPAN_CTX = DubboCtxKey("tracing.remote.span.ctx")
 )
 
 // Use for router module
diff --git a/common/url.go b/common/url.go
index 87cacfd..ac49465 100644
--- a/common/url.go
+++ b/common/url.go
@@ -90,9 +90,7 @@ type baseUrl struct {
 	Location string // ip+port
 	Ip       string
 	Port     string
-	//url.Values is not safe map, add to avoid concurrent map read and map write error
-	paramsLock   sync.RWMutex
-	params       url.Values
+
 	PrimitiveURL string
 }
 
@@ -116,6 +114,10 @@ type URL struct {
 	noCopy noCopy
 
 	baseUrl
+	//url.Values is not safe map, add to avoid concurrent map read and map write error
+	paramsLock sync.RWMutex
+	params     url.Values
+
 	Path     string // like  /com.ikurento.dubbo.UserProvider
 	Username string
 	Password string
diff --git a/common/url_test.go b/common/url_test.go
index 4008f6a..c645f1a 100644
--- a/common/url_test.go
+++ b/common/url_test.go
@@ -161,7 +161,10 @@ func TestURLEqual(t *testing.T) {
 func TestURLGetParam(t *testing.T) {
 	params := url.Values{}
 	params.Set("key", "value")
-	u := URL{baseUrl: baseUrl{params: params}}
+
+	u := URL{}
+	u.SetParams(params)
+
 	v := u.GetParam("key", "default")
 	assert.Equal(t, "value", v)
 
@@ -172,8 +175,11 @@ func TestURLGetParam(t *testing.T) {
 
 func TestURLGetParamInt(t *testing.T) {
 	params := url.Values{}
-	params.Set("key", "")
-	u := URL{baseUrl: baseUrl{params: params}}
+	params.Set("key", "value")
+
+	u := URL{}
+	u.SetParams(params)
+
 	v := u.GetParamInt("key", 1)
 	assert.Equal(t, int64(1), v)
 
@@ -185,7 +191,10 @@ func TestURLGetParamInt(t *testing.T) {
 func TestURLGetParamIntValue(t *testing.T) {
 	params := url.Values{}
 	params.Set("key", "0")
-	u := URL{baseUrl: baseUrl{params: params}}
+
+	u := URL{}
+	u.SetParams(params)
+
 	v := u.GetParamInt("key", 1)
 	assert.Equal(t, int64(0), v)
 
@@ -197,7 +206,10 @@ func TestURLGetParamIntValue(t *testing.T) {
 func TestURLGetParamBool(t *testing.T) {
 	params := url.Values{}
 	params.Set("force", "true")
-	u := URL{baseUrl: baseUrl{params: params}}
+
+	u := URL{}
+	u.SetParams(params)
+
 	v := u.GetParamBool("force", false)
 	assert.Equal(t, true, v)
 
@@ -210,7 +222,10 @@ func TestURLGetParamAndDecoded(t *testing.T) {
 	rule := "host = 2.2.2.2,1.1.1.1,3.3.3.3 & host !=1.1.1.1 => host = 1.2.3.4"
 	params := url.Values{}
 	params.Set("rule", base64.URLEncoding.EncodeToString([]byte(rule)))
-	u := URL{baseUrl: baseUrl{params: params}}
+
+	u := URL{}
+	u.SetParams(params)
+
 	v, _ := u.GetParamAndDecoded("rule")
 	assert.Equal(t, rule, v)
 }
@@ -247,7 +262,10 @@ func TestURLToMap(t *testing.T) {
 func TestURLGetMethodParamInt(t *testing.T) {
 	params := url.Values{}
 	params.Set("methods.GetValue.timeout", "3")
-	u := URL{baseUrl: baseUrl{params: params}}
+
+	u := URL{}
+	u.SetParams(params)
+
 	v := u.GetMethodParamInt("GetValue", "timeout", 1)
 	assert.Equal(t, int64(3), v)
 
@@ -259,7 +277,10 @@ func TestURLGetMethodParamInt(t *testing.T) {
 func TestURLGetMethodParam(t *testing.T) {
 	params := url.Values{}
 	params.Set("methods.GetValue.timeout", "3s")
-	u := URL{baseUrl: baseUrl{params: params}}
+
+	u := URL{}
+	u.SetParams(params)
+
 	v := u.GetMethodParam("GetValue", "timeout", "1s")
 	assert.Equal(t, "3s", v)
 
@@ -271,7 +292,10 @@ func TestURLGetMethodParam(t *testing.T) {
 func TestURLGetMethodParamBool(t *testing.T) {
 	params := url.Values{}
 	params.Set("methods.GetValue.async", "true")
-	u := URL{baseUrl: baseUrl{params: params}}
+
+	u := URL{}
+	u.SetParams(params)
+
 	v := u.GetMethodParamBool("GetValue", "async", false)
 	assert.Equal(t, true, v)
 
diff --git a/config_center/apollo/listener.go b/config_center/apollo/listener.go
index ace5ed0..44d3255 100644
--- a/config_center/apollo/listener.go
+++ b/config_center/apollo/listener.go
@@ -36,7 +36,7 @@ type apolloListener struct {
 // nolint
 func newApolloListener() *apolloListener {
 	return &apolloListener{
-		listeners: make(map[config_center.ConfigurationListener]struct{}, 0),
+		listeners: make(map[config_center.ConfigurationListener]struct{}),
 	}
 }
 
diff --git a/filter/filter_impl/tps/tps_limiter_method_service_test.go b/filter/filter_impl/tps/tps_limiter_method_service_test.go
index a70287e..4ff0a23 100644
--- a/filter/filter_impl/tps/tps_limiter_method_service_test.go
+++ b/filter/filter_impl/tps/tps_limiter_method_service_test.go
@@ -113,7 +113,7 @@ func TestMethodServiceTpsLimiterImplIsAllowableMethodLevelOverride(t *testing.T)
 func TestMethodServiceTpsLimiterImplIsAllowableBothMethodAndService(t *testing.T) {
 	methodName := "hello3"
 	methodConfigPrefix := "methods." + methodName + "."
-	invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]interface{}, 0))
+	invoc := invocation.NewRPCInvocation(methodName, []interface{}{"OK"}, make(map[string]interface{}))
 	ctrl := gomock.NewController(t)
 	defer ctrl.Finish()
 
diff --git a/protocol/dubbo/hessian2/hessian_dubbo.go b/protocol/dubbo/hessian2/hessian_dubbo.go
index 1afa4ec..55a824a 100644
--- a/protocol/dubbo/hessian2/hessian_dubbo.go
+++ b/protocol/dubbo/hessian2/hessian_dubbo.go
@@ -99,7 +99,7 @@ func (h *HessianCodec) Write(service Service, header DubboHeader, body interface
 		return packResponse(header, body)
 
 	default:
-		return nil, perrors.Errorf("Unrecognised message type: %v", header.Type)
+		return nil, perrors.Errorf("Unrecognized message type: %v", header.Type)
 	}
 
 	// unreachable return nil, nil
diff --git a/protocol/dubbo/impl/codec.go b/protocol/dubbo/impl/codec.go
index 17e7b57..6c9816f 100644
--- a/protocol/dubbo/impl/codec.go
+++ b/protocol/dubbo/impl/codec.go
@@ -146,7 +146,7 @@ func (c *ProtocolCodec) Encode(p DubboPackage) ([]byte, error) {
 		return packResponse(p, c.serializer)
 
 	default:
-		return nil, perrors.Errorf("Unrecognised message type: %v", header.Type)
+		return nil, perrors.Errorf("Unrecognized message type: %v", header.Type)
 	}
 }
 
diff --git a/remoting/getty/listener.go b/remoting/getty/listener.go
index b2f7790..f402411 100644
--- a/remoting/getty/listener.go
+++ b/remoting/getty/listener.go
@@ -101,7 +101,7 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
 		logger.Errorf("illegal package")
 		return
 	}
-	// get heartbeart request from server
+	// get heartbeat request from server
 	if result.IsRequest {
 		req := result.Result.(*remoting.Request)
 		if req.Event {
@@ -114,12 +114,12 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
 			reply(session, resp)
 			return
 		}
-		logger.Errorf("illegal request but not heartbeart. {%#v}", req)
+		logger.Errorf("illegal request but not heartbeat. {%#v}", req)
 		return
 	}
 	h.timeoutTimes = 0
 	p := result.Result.(*remoting.Response)
-	// get heartbeart
+	// get heartbeat
 	if p.Event {
 		logger.Debugf("get rpc heartbeat response{%#v}", p)
 		if p.Error != nil {
@@ -138,7 +138,7 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
 
 // OnCron check the session health periodic. if the session's sessionTimeout has reached, just close the session
 func (h *RpcClientHandler) OnCron(session getty.Session) {
-	rpcSession, err := h.conn.getClientRpcSession(session)
+	rs, err := h.conn.getClientRpcSession(session)
 	if err != nil {
 		logger.Errorf("client.getClientSession(session{%s}) = error{%v}",
 			session.Stat(), perrors.WithStack(err))
@@ -146,7 +146,7 @@ func (h *RpcClientHandler) OnCron(session getty.Session) {
 	}
 	if h.conn.pool.rpcClient.conf.sessionTimeout.Nanoseconds() < time.Since(session.GetActive()).Nanoseconds() {
 		logger.Warnf("session{%s} timeout{%s}, reqNum{%d}",
-			session.Stat(), time.Since(session.GetActive()).String(), rpcSession.reqNum)
+			session.Stat(), time.Since(session.GetActive()).String(), rs.reqNum)
 		h.conn.removeSession(session) // -> h.conn.close() -> h.conn.pool.remove(h.conn)
 		return
 	}
diff --git a/remoting/getty/listener_test.go b/remoting/getty/listener_test.go
index 956ecf9..2700ed8 100644
--- a/remoting/getty/listener_test.go
+++ b/remoting/getty/listener_test.go
@@ -23,14 +23,14 @@ import (
 )
 
 import (
+	"github.com/opentracing/opentracing-go"
+	"github.com/opentracing/opentracing-go/mocktracer"
 	"github.com/stretchr/testify/assert"
 )
 
 import (
 	"github.com/apache/dubbo-go/common/constant"
 	"github.com/apache/dubbo-go/protocol/invocation"
-	"github.com/opentracing/opentracing-go"
-	"github.com/opentracing/opentracing-go/mocktracer"
 )
 
 // test rebuild the ctx
@@ -63,7 +63,7 @@ func TestRebuildCtx(t *testing.T) {
 // Once we decided to transfer more context's key-value, we should change this.
 // now we only support rebuild the tracing context
 func rebuildCtx(inv *invocation.RPCInvocation) context.Context {
-	ctx := context.WithValue(context.Background(), "attachment", inv.Attachments())
+	ctx := context.WithValue(context.Background(), constant.DubboCtxKey("attachment"), inv.Attachments())
 
 	// actually, if user do not use any opentracing framework, the err will not be nil.
 	spanCtx, err := opentracing.GlobalTracer().Extract(opentracing.TextMap,