You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/05/10 07:07:31 UTC

[GitHub] [dubbo-go] yongjiapro opened a new pull request #1196: feature: Add a ResultGenericService that returns provider's attachments

yongjiapro opened a new pull request #1196:
URL: https://github.com/apache/dubbo-go/pull/1196


   <!--  Thanks for sending a pull request!
   Read https://github.com/apache/dubbo-go/blob/master/contributing.md before commit pull request.
   -->
   
   **What this PR does**:
   
   增加ResultGenericService,支持泛调用获取Provider返回的Attachments.
   
   **Which issue(s) this PR fixes**:
   <!--
   *Automatically closes linked issue when PR is merged.
   Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
   _If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
   -->
   Fixes #
   
   **Special notes for your reviewer**:
   
   在网关场景中,网关通过GenericService调用业务Provider,除了返回业务数据外,还需要利用Attachment机制隐式传值以实现一些扩展功能。
   
   **Does this PR introduce a user-facing change?**:
   <!--
   If no, just write "NONE" in the release-note block below.
   If yes, a release note is required:
   Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
   -->
   ```release-note
   feature: Add a ResultGenericService that returns provider's attachments
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #1196: feature: Add a ResultGenericService that returns provider's attachments

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on a change in pull request #1196:
URL: https://github.com/apache/dubbo-go/pull/1196#discussion_r629175707



##########
File path: common/proxy/proxy_factory/result.go
##########
@@ -0,0 +1,144 @@
+/*
+ * 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 proxy_factory
+
+import (
+	"context"
+	"github.com/apache/dubbo-go/common"
+	"github.com/apache/dubbo-go/common/constant"
+	"github.com/apache/dubbo-go/common/logger"
+	"github.com/apache/dubbo-go/common/proxy"
+	"github.com/apache/dubbo-go/protocol"
+	"github.com/apache/dubbo-go/protocol/invocation"
+	"reflect"
+)
+
+var (
+	typeOfInterface = reflect.Zero(reflect.TypeOf((*interface{})(nil)).Elem()).Type()
+	typeOfResult    = reflect.Zero(reflect.TypeOf((*protocol.Result)(nil)).Elem()).Type()
+)
+
+// ResultProxyFactory proxy factory, return a protocol.Result with attachments
+type ResultProxyFactory struct {
+}
+
+// NewResultProxyFactory returns a proxy factory instance
+func NewResultProxyFactory(_ ...proxy.Option) proxy.ProxyFactory {
+	return &ResultProxyFactory{}
+}
+
+func (f *ResultProxyFactory) GetProxy(invoker protocol.Invoker, url *common.URL) *proxy.Proxy {
+	return f.GetAsyncProxy(invoker, nil, url)
+}
+
+func (f *ResultProxyFactory) GetAsyncProxy(invoker protocol.Invoker, callBack interface{}, url *common.URL) *proxy.Proxy {

Review comment:
       add comment for public func, pls.

##########
File path: common/proxy/proxy_factory/result.go
##########
@@ -0,0 +1,144 @@
+/*
+ * 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 proxy_factory
+
+import (
+	"context"
+	"github.com/apache/dubbo-go/common"
+	"github.com/apache/dubbo-go/common/constant"
+	"github.com/apache/dubbo-go/common/logger"
+	"github.com/apache/dubbo-go/common/proxy"
+	"github.com/apache/dubbo-go/protocol"
+	"github.com/apache/dubbo-go/protocol/invocation"
+	"reflect"
+)
+
+var (
+	typeOfInterface = reflect.Zero(reflect.TypeOf((*interface{})(nil)).Elem()).Type()
+	typeOfResult    = reflect.Zero(reflect.TypeOf((*protocol.Result)(nil)).Elem()).Type()
+)
+
+// ResultProxyFactory proxy factory, return a protocol.Result with attachments
+type ResultProxyFactory struct {
+}
+
+// NewResultProxyFactory returns a proxy factory instance
+func NewResultProxyFactory(_ ...proxy.Option) proxy.ProxyFactory {
+	return &ResultProxyFactory{}
+}
+
+func (f *ResultProxyFactory) GetProxy(invoker protocol.Invoker, url *common.URL) *proxy.Proxy {
+	return f.GetAsyncProxy(invoker, nil, url)
+}
+
+func (f *ResultProxyFactory) GetAsyncProxy(invoker protocol.Invoker, callBack interface{}, url *common.URL) *proxy.Proxy {
+	attrs := map[string]string{}
+	attrs[constant.ASYNC_KEY] = url.GetParam(constant.ASYNC_KEY, "false")
+	return proxy.NewProxyWithOptions(invoker, callBack, attrs,
+		proxy.WithProxyImplementFunc(NewResultProxyImplFunc(attrs)))
+}
+
+// GetInvoker gets a invoker
+func (f *ResultProxyFactory) GetInvoker(url *common.URL) protocol.Invoker {
+	return &ProxyInvoker{
+		BaseInvoker: *protocol.NewBaseInvoker(url),
+	}
+}
+
+func NewResultProxyImplFunc(attr map[string]string) proxy.ImplementFunc {

Review comment:
       add comment for public func, pls.

##########
File path: common/proxy/proxy_factory/result.go
##########
@@ -0,0 +1,144 @@
+/*
+ * 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 proxy_factory
+
+import (
+	"context"
+	"github.com/apache/dubbo-go/common"
+	"github.com/apache/dubbo-go/common/constant"
+	"github.com/apache/dubbo-go/common/logger"
+	"github.com/apache/dubbo-go/common/proxy"
+	"github.com/apache/dubbo-go/protocol"
+	"github.com/apache/dubbo-go/protocol/invocation"
+	"reflect"
+)
+
+var (
+	typeOfInterface = reflect.Zero(reflect.TypeOf((*interface{})(nil)).Elem()).Type()
+	typeOfResult    = reflect.Zero(reflect.TypeOf((*protocol.Result)(nil)).Elem()).Type()
+)
+
+// ResultProxyFactory proxy factory, return a protocol.Result with attachments
+type ResultProxyFactory struct {
+}
+
+// NewResultProxyFactory returns a proxy factory instance
+func NewResultProxyFactory(_ ...proxy.Option) proxy.ProxyFactory {
+	return &ResultProxyFactory{}
+}
+
+func (f *ResultProxyFactory) GetProxy(invoker protocol.Invoker, url *common.URL) *proxy.Proxy {

Review comment:
       add comment for public func, pls.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #1196: feature: Add a ResultGenericService that returns provider's attachments

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on a change in pull request #1196:
URL: https://github.com/apache/dubbo-go/pull/1196#discussion_r629172697



##########
File path: config/generic_service_result.go
##########
@@ -0,0 +1,41 @@
+/*
+ * 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 config
+
+import (

Review comment:
       split it




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [dubbo-go] yongjiapro commented on a change in pull request #1196: feature: Add a ResultGenericService that returns provider's attachments

Posted by GitBox <gi...@apache.org>.
yongjiapro commented on a change in pull request #1196:
URL: https://github.com/apache/dubbo-go/pull/1196#discussion_r632311124



##########
File path: config/generic_service_result.go
##########
@@ -0,0 +1,44 @@
+/*
+ * 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 config
+
+import (
+	"context"
+)
+
+import (
+	"github.com/apache/dubbo-go/protocol"
+)
+
+// ResultGenericService uses for generic invoke for service call,
+// Unlike GenericService, it returns the original <protocol.Result> type object called by DubboRPC,
+// which contains the Attachments data returned by the DubboProvider interface
+type ResultGenericService struct {
+	Invoke       func(ctx context.Context, args []interface{}) protocol.Result `dubbo:"$invoke"`

Review comment:
       在泛调用场景,Result封装了(Result, Attachment, Error)。
   把它们拆分出来的话,基于怎样的考虑呢?考虑符合Go的习惯用法么?还是说对于protocol包的引用依赖呢?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [dubbo-go] fangyincheng commented on a change in pull request #1196: feature: Add a ResultGenericService that returns provider's attachments

Posted by GitBox <gi...@apache.org>.
fangyincheng commented on a change in pull request #1196:
URL: https://github.com/apache/dubbo-go/pull/1196#discussion_r635031131



##########
File path: config/generic_service_result.go
##########
@@ -0,0 +1,44 @@
+/*
+ * 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 config
+
+import (
+	"context"
+)
+
+import (
+	"github.com/apache/dubbo-go/protocol"
+)
+
+// ResultGenericService uses for generic invoke for service call,
+// Unlike GenericService, it returns the original <protocol.Result> type object called by DubboRPC,
+// which contains the Attachments data returned by the DubboProvider interface
+type ResultGenericService struct {
+	Invoke       func(ctx context.Context, args []interface{}) protocol.Result `dubbo:"$invoke"`

Review comment:
       因为result是定义再protocol里面的结构,如果后面有什么改动可能会修改里面的字段。
   但是你需要的只是result,attachment,error,建议这个Result结构体不对用户暴露。你可以把它重新封装一个新的结构。
   另外,(res, error)这种方式是比较符合go的风格的吧。




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [dubbo-go] fangyincheng commented on pull request #1196: feature: Add a new GenericService that returns provider's attachments

Posted by GitBox <gi...@apache.org>.
fangyincheng commented on pull request #1196:
URL: https://github.com/apache/dubbo-go/pull/1196#issuecomment-860165869


   please fix ut


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #1196: feature: Add a ResultGenericService that returns provider's attachments

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on a change in pull request #1196:
URL: https://github.com/apache/dubbo-go/pull/1196#discussion_r629170113



##########
File path: common/proxy/proxy_factory/result.go
##########
@@ -0,0 +1,144 @@
+/*
+ * 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 proxy_factory
+
+import (

Review comment:
       split it




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [dubbo-go] fangyincheng commented on a change in pull request #1196: feature: Add a ResultGenericService that returns provider's attachments

Posted by GitBox <gi...@apache.org>.
fangyincheng commented on a change in pull request #1196:
URL: https://github.com/apache/dubbo-go/pull/1196#discussion_r629851796



##########
File path: config/generic_service_result.go
##########
@@ -0,0 +1,44 @@
+/*
+ * 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 config
+
+import (
+	"context"
+)
+
+import (
+	"github.com/apache/dubbo-go/protocol"
+)
+
+// ResultGenericService uses for generic invoke for service call,
+// Unlike GenericService, it returns the original <protocol.Result> type object called by DubboRPC,
+// which contains the Attachments data returned by the DubboProvider interface
+type ResultGenericService struct {
+	Invoke       func(ctx context.Context, args []interface{}) protocol.Result `dubbo:"$invoke"`

Review comment:
       是否可以不用protocol。Result向用户返回呢?用多返回值?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [dubbo-go] yongjiapro commented on a change in pull request #1196: feature: Add a ResultGenericService that returns provider's attachments

Posted by GitBox <gi...@apache.org>.
yongjiapro commented on a change in pull request #1196:
URL: https://github.com/apache/dubbo-go/pull/1196#discussion_r632311124



##########
File path: config/generic_service_result.go
##########
@@ -0,0 +1,44 @@
+/*
+ * 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 config
+
+import (
+	"context"
+)
+
+import (
+	"github.com/apache/dubbo-go/protocol"
+)
+
+// ResultGenericService uses for generic invoke for service call,
+// Unlike GenericService, it returns the original <protocol.Result> type object called by DubboRPC,
+// which contains the Attachments data returned by the DubboProvider interface
+type ResultGenericService struct {
+	Invoke       func(ctx context.Context, args []interface{}) protocol.Result `dubbo:"$invoke"`

Review comment:
       在泛调用场景,Result封装了(Result, Attachment, Error)多值。




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [dubbo-go] AlexStocks merged pull request #1196: feature: Add a new GenericService that returns provider's attachments

Posted by GitBox <gi...@apache.org>.
AlexStocks merged pull request #1196:
URL: https://github.com/apache/dubbo-go/pull/1196


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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