Skip to content

Commit

Permalink
fix ctx linter error
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks committed Jan 4, 2021
1 parent ca71862 commit 9e40791
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 25 deletions.
63 changes: 63 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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"

2 changes: 1 addition & 1 deletion common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
42 changes: 33 additions & 9 deletions common/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)
}
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion config_center/apollo/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion filter/filter_impl/tps/tps_limiter_method_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion protocol/dubbo/hessian2/hessian_dubbo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion protocol/dubbo/impl/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
10 changes: 5 additions & 5 deletions remoting/getty/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -138,15 +138,15 @@ 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))
return
}
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
}
Expand Down
6 changes: 3 additions & 3 deletions remoting/getty/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9e40791

Please sign in to comment.