From b59d85ad9f30154a3cc3945bcaa75d8b55d6d21a Mon Sep 17 00:00:00 2001
From: flycash <ming_flycash@qq.com>
Date: Sun, 19 Jan 2020 14:54:55 +0800
Subject: [PATCH] Using default context.Context.

---
 filter/filter_impl/generic_service_filter.go |  1 +
 filter/filter_impl/tracing_filter.go         |  2 +-
 protocol/context.go                          | 33 --------------------
 protocol/invocation.go                       |  5 +--
 protocol/invocation/rpcinvocation.go         | 12 ++++---
 5 files changed, 13 insertions(+), 40 deletions(-)
 delete mode 100644 protocol/context.go

diff --git a/filter/filter_impl/generic_service_filter.go b/filter/filter_impl/generic_service_filter.go
index da33f13e5..44cb5751e 100644
--- a/filter/filter_impl/generic_service_filter.go
+++ b/filter/filter_impl/generic_service_filter.go
@@ -106,6 +106,7 @@ func (ef *GenericServiceFilter) Invoke(invoker protocol.Invoker, invocation prot
 		newParams[i] = newParam
 	}
 	newInvocation := invocation2.NewRPCInvocation(methodName, newParams, invocation.Attachments())
+	newInvocation.SetContext(invocation.Context())
 	newInvocation.SetReply(invocation.Reply())
 	return invoker.Invoke(newInvocation)
 }
diff --git a/filter/filter_impl/tracing_filter.go b/filter/filter_impl/tracing_filter.go
index d1d68de87..dc1e8c314 100644
--- a/filter/filter_impl/tracing_filter.go
+++ b/filter/filter_impl/tracing_filter.go
@@ -56,7 +56,7 @@ func (tf *tracingFilter) Invoke(invoker protocol.Invoker, invocation protocol.In
 	// withTimeout after we support the timeout between different ends.
 	invCtx, cancel := context.WithCancel(invocation.Context())
 	span, spanCtx := opentracing.StartSpanFromContext(invCtx, operationName)
-	invocation.SetContext(protocol.NewContextWith(spanCtx))
+	invocation.SetContext(spanCtx)
 	defer func() {
 		span.Finish()
 		cancel()
diff --git a/protocol/context.go b/protocol/context.go
deleted file mode 100644
index e2d22785e..000000000
--- a/protocol/context.go
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package protocol
-
-import (
-	"context"
-)
-
-type Context struct {
-	context.Context
-}
-
-func NewContext() Context {
-	return NewContextWith(context.Background())
-}
-func NewContextWith(ctx context.Context) Context {
-	return Context{Context: ctx}
-}
diff --git a/protocol/invocation.go b/protocol/invocation.go
index 5bc82e77e..baf6e5c08 100644
--- a/protocol/invocation.go
+++ b/protocol/invocation.go
@@ -18,6 +18,7 @@
 package protocol
 
 import (
+	"context"
 	"reflect"
 )
 
@@ -29,6 +30,6 @@ type Invocation interface {
 	Attachments() map[string]string
 	AttachmentsByKey(string, string) string
 	Invoker() Invoker
-	Context() Context
-	SetContext(ctx Context)
+	Context() context.Context
+	SetContext(ctx context.Context)
 }
diff --git a/protocol/invocation/rpcinvocation.go b/protocol/invocation/rpcinvocation.go
index f56c9e9d0..91a377a13 100644
--- a/protocol/invocation/rpcinvocation.go
+++ b/protocol/invocation/rpcinvocation.go
@@ -18,6 +18,7 @@
 package invocation
 
 import (
+	"context"
 	"reflect"
 	"sync"
 )
@@ -39,7 +40,7 @@ type RPCInvocation struct {
 	attachments    map[string]string
 	invoker        protocol.Invoker
 	lock           sync.RWMutex
-	ctx            protocol.Context
+	ctx            context.Context
 }
 
 func NewRPCInvocation(methodName string, arguments []interface{}, attachments map[string]string) *RPCInvocation {
@@ -47,11 +48,14 @@ func NewRPCInvocation(methodName string, arguments []interface{}, attachments ma
 		methodName:  methodName,
 		arguments:   arguments,
 		attachments: attachments,
+		ctx:         context.Background(),
 	}
 }
 
 func NewRPCInvocationWithOptions(opts ...option) *RPCInvocation {
-	invo := &RPCInvocation{}
+	invo := &RPCInvocation{
+		ctx: context.Background(),
+	}
 	for _, opt := range opts {
 		opt(invo)
 	}
@@ -120,11 +124,11 @@ func (r *RPCInvocation) SetCallBack(c interface{}) {
 	r.callBack = c
 }
 
-func (r *RPCInvocation) Context() protocol.Context {
+func (r *RPCInvocation) Context() context.Context {
 	return r.ctx
 }
 
-func (r *RPCInvocation) SetContext(ctx protocol.Context) {
+func (r *RPCInvocation) SetContext(ctx context.Context) {
 	r.ctx = ctx
 }
 
-- 
GitLab