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 2022/04/22 12:45:57 UTC

[GitHub] [dubbo-go] complone opened a new pull request, #1855: feat: Rest protocol Support

complone opened a new pull request, #1855:
URL: https://github.com/apache/dubbo-go/pull/1855

   <!--  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**: 
   
   **Which issue(s) this PR fixes**: 
   Fixes #
   
   Support Rest Protocol
   
   **You should pay attention to items below to ensure your pr passes our ci test**
   dubbo3_protocol_test.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.

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


[GitHub] [dubbo-go] complone commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
complone commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r873495860


##########
config/rest_config.go:
##########
@@ -46,12 +59,107 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
 	return nil
 }
 
+// pi todo refactor
+func (c *RestConsumerConfig) Init(rc *RootConfig) error {
+	restConsumerConfig := rc.RestConsumer
+
+	if restConsumerConfig == nil {
+		logger.Debugf("[rest-protocol] no consumer config")
+		return nil
+	}
+
+	restConsumerServiceConfigMap := make(map[string]*RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))
+	for key, rc := range restConsumerConfig.RestServiceConfigsMap {
+		rc.Client = getNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DefaultRestClient)
+		rc.RestMethodConfigs = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
+		restConsumerServiceConfigMap[key] = rc
+	}
+
+	SetRestConsumerServiceConfigMap(restConsumerServiceConfigMap)
+
+	return nil
+}
+
+// initProviderRestConfig ...
+func initMethodConfigMap(rc *RestServiceConfig, consumes string, produces string) map[string]*RestMethodConfig {
+	mcm := make(map[string]*RestMethodConfig, len(rc.RestMethodConfigs))
+	for _, mc := range rc.RestMethodConfigs {
+		mc.InterfaceName = rc.InterfaceName
+		mc.Path = rc.Path + mc.Path
+		mc.Consumes = getNotEmptyStr(mc.Consumes, rc.Consumes, consumes)
+		mc.Produces = getNotEmptyStr(mc.Produces, rc.Produces, produces)
+		mc.MethodType = getNotEmptyStr(mc.MethodType, rc.MethodType)
+		mc = transformMethodConfig(mc)
+		mcm[mc.MethodName] = mc
+	}
+	return mcm
+}
+
+// transformMethodConfig
+func transformMethodConfig(methodConfig *RestMethodConfig) *RestMethodConfig {
+	if len(methodConfig.PathParamsMap) == 0 && len(methodConfig.PathParams) > 0 {
+		paramsMap, err := parseParamsString2Map(methodConfig.PathParams)
+		if err != nil {
+			logger.Warnf("[RestConfig] Path Param parse error:%v", err)
+		} else {
+			methodConfig.PathParamsMap = paramsMap
+		}
+	}
+	if len(methodConfig.QueryParamsMap) == 0 && len(methodConfig.QueryParams) > 0 {
+		paramsMap, err := parseParamsString2Map(methodConfig.QueryParams)
+		if err != nil {
+			logger.Warnf("[RestConfig] Query Param parse error:%v", err)
+		} else {
+			methodConfig.QueryParamsMap = paramsMap
+		}
+	}
+	if len(methodConfig.HeadersMap) == 0 && len(methodConfig.Headers) > 0 {
+		headersMap, err := parseParamsString2Map(methodConfig.Headers)
+		if err != nil {
+			logger.Warnf("[RestConfig] Header parse error:%v", err)
+		} else {
+			methodConfig.HeadersMap = headersMap
+		}
+	}
+	return methodConfig
+}
+
+// transform a string to a map
+// for example:
+// string "0:id,1:name" => map [0:id,1:name]
+func parseParamsString2Map(params string) (map[int]string, error) {
+	m := make(map[int]string, 8)
+	for _, p := range strings.Split(params, ",") {
+		pa := strings.Split(p, ":")
+		key, err := strconv.Atoi(pa[0])
+		if err != nil {
+			return nil, err
+		}
+		m[key] = pa[1]
+	}
+	return m, nil
+}
+
+// function will return first not empty string ..
+func getNotEmptyStr(args ...string) string {

Review Comment:
   solved



-- 
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


[GitHub] [dubbo-go] pherzheyu commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
pherzheyu commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r866414236


##########
cluster/cluster/adaptivesvc/cluster_invoker.go:
##########
@@ -35,6 +31,8 @@ import (
 	"dubbo.apache.org/dubbo-go/v3/common/extension"
 	"dubbo.apache.org/dubbo-go/v3/common/logger"
 	"dubbo.apache.org/dubbo-go/v3/protocol"
+
+	perrors "github.com/pkg/errors"

Review Comment:
   这里是不是没运行imports-formatter,import分组不正确ci过不了的



-- 
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


[GitHub] [dubbo-go] justxuewei commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
justxuewei commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r884801802


##########
config/rest_config.go:
##########
@@ -46,12 +59,94 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
 	return nil
 }
 
+
+func (c *RestConsumerConfig) Init(rc *RootConfig) error {
+	restConsumerConfig := rc.RestConsumer
+
+	if restConsumerConfig == nil {
+		logger.Debugf("[rest-protocol] no consumer config")
+		return nil
+	}
+
+	restConsumerServiceConfigMap := make(map[string]*RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))
+	for key, rc := range restConsumerConfig.RestServiceConfigsMap {
+		rc.Client = common.GetNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DefaultRestClient)
+		rc.RestMethodConfigs = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
+		restConsumerServiceConfigMap[key] = rc
+	}
+
+	SetRestConsumerServiceConfigMap(restConsumerServiceConfigMap)
+
+	return nil
+}
+
+// initProviderRestConfig ...
+func initMethodConfigMap(rc *RestServiceConfig, consumes string, produces string) map[string]*RestMethodConfig {
+	mcm := make(map[string]*RestMethodConfig, len(rc.RestMethodConfigs))
+	for _, mc := range rc.RestMethodConfigs {
+		mc.InterfaceName = rc.InterfaceName
+		mc.Path = rc.Path + mc.Path
+		mc.Consumes = common.GetNotEmptyStr(mc.Consumes, rc.Consumes, consumes)
+		mc.Produces = common.GetNotEmptyStr(mc.Produces, rc.Produces, produces)
+		mc.MethodType = common.GetNotEmptyStr(mc.MethodType, rc.MethodType)
+		mc = transformMethodConfig(mc)
+		mcm[mc.MethodName] = mc
+	}
+	return mcm
+}
+
+// transformMethodConfig
+func transformMethodConfig(methodConfig *RestMethodConfig) *RestMethodConfig {

Review Comment:
   The methodConfig is a type of pointer, why do you return a pointer again?



-- 
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


[GitHub] [dubbo-go] justxuewei commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
justxuewei commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r884805166


##########
config/router_config_test.go:
##########
@@ -55,14 +55,6 @@ func TestString(t *testing.T) {
 	assert.Equal(t, n2[1], "")
 }
 
-func TestRouterInit(t *testing.T) {
-	//err := RouterInit(testVirtualServiceYML, testDestinationRuleYML)
-	//assert.NoError(t, err)
-	//
-	//err = RouterInit(testVirtualServiceYML, errorTestDestinationRuleYML)
-	//assert.Error(t, err)
-}

Review Comment:
   Is this unit test still useful? 



-- 
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


[GitHub] [dubbo-go] justxuewei commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
justxuewei commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r885137373


##########
config/rest_config.go:
##########
@@ -46,12 +59,94 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
 	return nil
 }
 
+
+func (c *RestConsumerConfig) Init(rc *RootConfig) error {
+	restConsumerConfig := rc.RestConsumer
+
+	if restConsumerConfig == nil {
+		logger.Debugf("[rest-protocol] no consumer config")
+		return nil
+	}
+
+	restConsumerServiceConfigMap := make(map[string]*RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))
+	for key, rc := range restConsumerConfig.RestServiceConfigsMap {
+		rc.Client = common.GetNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DefaultRestClient)
+		rc.RestMethodConfigs = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
+		restConsumerServiceConfigMap[key] = rc
+	}
+
+	SetRestConsumerServiceConfigMap(restConsumerServiceConfigMap)
+
+	return nil
+}
+
+// initProviderRestConfig ...
+func initMethodConfigMap(rc *RestServiceConfig, consumes string, produces string) map[string]*RestMethodConfig {
+	mcm := make(map[string]*RestMethodConfig, len(rc.RestMethodConfigs))
+	for _, mc := range rc.RestMethodConfigs {
+		mc.InterfaceName = rc.InterfaceName
+		mc.Path = rc.Path + mc.Path
+		mc.Consumes = common.GetNotEmptyStr(mc.Consumes, rc.Consumes, consumes)
+		mc.Produces = common.GetNotEmptyStr(mc.Produces, rc.Produces, produces)
+		mc.MethodType = common.GetNotEmptyStr(mc.MethodType, rc.MethodType)
+		mc = transformMethodConfig(mc)
+		mcm[mc.MethodName] = mc
+	}
+	return mcm
+}
+
+// transformMethodConfig
+func transformMethodConfig(methodConfig *RestMethodConfig) *RestMethodConfig {

Review Comment:
   Yes, I am saying that the **return value** could be removed, cuz the type of the `methodConfig` on the parameter is a pointer.
   
   Specifically, the signature of the method should be `func transformMethodConfig(methodConfig *RestMethodConfig)` instead of `func transformMethodConfig(methodConfig *RestMethodConfig) *RestMethodConfig`.



-- 
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


[GitHub] [dubbo-go] complone commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
complone commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r866449388


##########
cluster/cluster/adaptivesvc/cluster_invoker.go:
##########
@@ -35,6 +31,8 @@ import (
 	"dubbo.apache.org/dubbo-go/v3/common/extension"
 	"dubbo.apache.org/dubbo-go/v3/common/logger"
 	"dubbo.apache.org/dubbo-go/v3/protocol"
+
+	perrors "github.com/pkg/errors"

Review Comment:
    imports-formatter -path . -module github.com/apache/dubbo-go -bl false 已运行



-- 
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


[GitHub] [dubbo-go] pherzheyu commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
pherzheyu commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r856307364


##########
protocol/rest/server/go_restful_server.go:
##########
@@ -34,17 +34,13 @@ import (
 
 import (
 	"dubbo.apache.org/dubbo-go/v3/common"
-	"dubbo.apache.org/dubbo-go/v3/common/constant"
-	"dubbo.apache.org/dubbo-go/v3/common/extension"
 	"dubbo.apache.org/dubbo-go/v3/common/logger"
-	"dubbo.apache.org/dubbo-go/v3/protocol/rest/config"
-	"dubbo.apache.org/dubbo-go/v3/protocol/rest/server"
+	"dubbo.apache.org/dubbo-go/v3/config"
 )
 
-func init() {
-	extension.SetRestServer(constant.DefaultRestServer, NewGoRestfulServer)
-}
-

Review Comment:
   没用的注释去掉,这个会影响godoc的提取



-- 
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


[GitHub] [dubbo-go] complone commented on pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
complone commented on PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#issuecomment-1126605267

   > ping @complone
   
   Corrections will be completed this week


-- 
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


[GitHub] [dubbo-go] pherzheyu commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
pherzheyu commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r856306020


##########
protocol/rest/server/rest_server.go:
##########
@@ -32,9 +32,9 @@ import (
 import (
 	"dubbo.apache.org/dubbo-go/v3/common"
 	"dubbo.apache.org/dubbo-go/v3/common/logger"
+	rest_config "dubbo.apache.org/dubbo-go/v3/config"

Review Comment:
   是否有重新命名的必要性,是否可以考虑把我们的代码规范用起来?



-- 
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


[GitHub] [dubbo-go] complone commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
complone commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r885192894


##########
config/rest_config.go:
##########
@@ -46,12 +59,94 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
 	return nil
 }
 
+
+func (c *RestConsumerConfig) Init(rc *RootConfig) error {
+	restConsumerConfig := rc.RestConsumer
+
+	if restConsumerConfig == nil {
+		logger.Debugf("[rest-protocol] no consumer config")
+		return nil
+	}
+
+	restConsumerServiceConfigMap := make(map[string]*RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))
+	for key, rc := range restConsumerConfig.RestServiceConfigsMap {
+		rc.Client = common.GetNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DefaultRestClient)
+		rc.RestMethodConfigs = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
+		restConsumerServiceConfigMap[key] = rc
+	}
+
+	SetRestConsumerServiceConfigMap(restConsumerServiceConfigMap)
+
+	return nil
+}
+
+// initProviderRestConfig ...
+func initMethodConfigMap(rc *RestServiceConfig, consumes string, produces string) map[string]*RestMethodConfig {
+	mcm := make(map[string]*RestMethodConfig, len(rc.RestMethodConfigs))
+	for _, mc := range rc.RestMethodConfigs {
+		mc.InterfaceName = rc.InterfaceName
+		mc.Path = rc.Path + mc.Path
+		mc.Consumes = common.GetNotEmptyStr(mc.Consumes, rc.Consumes, consumes)
+		mc.Produces = common.GetNotEmptyStr(mc.Produces, rc.Produces, produces)
+		mc.MethodType = common.GetNotEmptyStr(mc.MethodType, rc.MethodType)
+		mc = transformMethodConfig(mc)
+		mcm[mc.MethodName] = mc
+	}
+	return mcm
+}
+
+// transformMethodConfig
+func transformMethodConfig(methodConfig *RestMethodConfig) *RestMethodConfig {

Review Comment:
   The return value cannot be deleted because RestServiceConfig needs to declare the pointer type RestMethodConfigs map[string]*RestMethodConfig



-- 
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


[GitHub] [dubbo-go] complone commented on pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
complone commented on PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#issuecomment-1138248505

   > 。
   
   OK, I'll see it in the evening


-- 
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


[GitHub] [dubbo-go] justxuewei commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
justxuewei commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r884802960


##########
config/rest_config.go:
##########
@@ -46,12 +59,94 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
 	return nil
 }
 
+
+func (c *RestConsumerConfig) Init(rc *RootConfig) error {
+	restConsumerConfig := rc.RestConsumer
+
+	if restConsumerConfig == nil {
+		logger.Debugf("[rest-protocol] no consumer config")
+		return nil
+	}
+
+	restConsumerServiceConfigMap := make(map[string]*RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))
+	for key, rc := range restConsumerConfig.RestServiceConfigsMap {
+		rc.Client = common.GetNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DefaultRestClient)
+		rc.RestMethodConfigs = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
+		restConsumerServiceConfigMap[key] = rc
+	}
+
+	SetRestConsumerServiceConfigMap(restConsumerServiceConfigMap)
+
+	return nil
+}
+
+// initProviderRestConfig ...
+func initMethodConfigMap(rc *RestServiceConfig, consumes string, produces string) map[string]*RestMethodConfig {
+	mcm := make(map[string]*RestMethodConfig, len(rc.RestMethodConfigs))
+	for _, mc := range rc.RestMethodConfigs {
+		mc.InterfaceName = rc.InterfaceName
+		mc.Path = rc.Path + mc.Path
+		mc.Consumes = common.GetNotEmptyStr(mc.Consumes, rc.Consumes, consumes)
+		mc.Produces = common.GetNotEmptyStr(mc.Produces, rc.Produces, produces)
+		mc.MethodType = common.GetNotEmptyStr(mc.MethodType, rc.MethodType)
+		mc = transformMethodConfig(mc)
+		mcm[mc.MethodName] = mc
+	}
+	return mcm
+}
+
+// transformMethodConfig
+func transformMethodConfig(methodConfig *RestMethodConfig) *RestMethodConfig {
+	if len(methodConfig.PathParamsMap) == 0 && len(methodConfig.PathParams) > 0 {
+		paramsMap, err := parseParamsString2Map(methodConfig.PathParams)
+		if err != nil {
+			logger.Warnf("[RestConfig] Path Param parse error:%v", err)
+		} else {
+			methodConfig.PathParamsMap = paramsMap
+		}
+	}
+	if len(methodConfig.QueryParamsMap) == 0 && len(methodConfig.QueryParams) > 0 {
+		paramsMap, err := parseParamsString2Map(methodConfig.QueryParams)
+		if err != nil {
+			logger.Warnf("[RestConfig] Query Param parse error:%v", err)
+		} else {
+			methodConfig.QueryParamsMap = paramsMap
+		}
+	}
+	if len(methodConfig.HeadersMap) == 0 && len(methodConfig.Headers) > 0 {
+		headersMap, err := parseParamsString2Map(methodConfig.Headers)
+		if err != nil {
+			logger.Warnf("[RestConfig] Header parse error:%v", err)
+		} else {
+			methodConfig.HeadersMap = headersMap
+		}
+	}
+	return methodConfig
+}
+
+// transform a string to a map
+// for example:
+// string "0:id,1:name" => map [0:id,1:name]
+func parseParamsString2Map(params string) (map[int]string, error) {
+	m := make(map[int]string, 8)

Review Comment:
   I think `m := make(map[int]string)` is enough, cuz the default length of map is 8.



-- 
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


[GitHub] [dubbo-go] complone commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
complone commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r885132813


##########
config/rest_config.go:
##########
@@ -46,12 +59,94 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
 	return nil
 }
 
+
+func (c *RestConsumerConfig) Init(rc *RootConfig) error {
+	restConsumerConfig := rc.RestConsumer
+
+	if restConsumerConfig == nil {
+		logger.Debugf("[rest-protocol] no consumer config")
+		return nil
+	}
+
+	restConsumerServiceConfigMap := make(map[string]*RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))
+	for key, rc := range restConsumerConfig.RestServiceConfigsMap {
+		rc.Client = common.GetNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DefaultRestClient)
+		rc.RestMethodConfigs = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
+		restConsumerServiceConfigMap[key] = rc
+	}
+
+	SetRestConsumerServiceConfigMap(restConsumerServiceConfigMap)
+
+	return nil
+}
+
+// initProviderRestConfig ...
+func initMethodConfigMap(rc *RestServiceConfig, consumes string, produces string) map[string]*RestMethodConfig {
+	mcm := make(map[string]*RestMethodConfig, len(rc.RestMethodConfigs))
+	for _, mc := range rc.RestMethodConfigs {
+		mc.InterfaceName = rc.InterfaceName
+		mc.Path = rc.Path + mc.Path
+		mc.Consumes = common.GetNotEmptyStr(mc.Consumes, rc.Consumes, consumes)
+		mc.Produces = common.GetNotEmptyStr(mc.Produces, rc.Produces, produces)
+		mc.MethodType = common.GetNotEmptyStr(mc.MethodType, rc.MethodType)
+		mc = transformMethodConfig(mc)
+		mcm[mc.MethodName] = mc
+	}
+	return mcm
+}
+
+// transformMethodConfig
+func transformMethodConfig(methodConfig *RestMethodConfig) *RestMethodConfig {

Review Comment:
   Because there is an object creation of RestMethodConfigs in the initMethodConfigMap method in rest_config.go In order to reduce the impact of object copying, a pointer is added



-- 
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


[GitHub] [dubbo-go] LaurenceLiZhixin merged pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
LaurenceLiZhixin merged PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855


-- 
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


[GitHub] [dubbo-go] justxuewei commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
justxuewei commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r885225709


##########
config/rest_config.go:
##########
@@ -46,12 +59,94 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
 	return nil
 }
 
+
+func (c *RestConsumerConfig) Init(rc *RootConfig) error {
+	restConsumerConfig := rc.RestConsumer
+
+	if restConsumerConfig == nil {
+		logger.Debugf("[rest-protocol] no consumer config")
+		return nil
+	}
+
+	restConsumerServiceConfigMap := make(map[string]*RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))
+	for key, rc := range restConsumerConfig.RestServiceConfigsMap {
+		rc.Client = common.GetNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DefaultRestClient)
+		rc.RestMethodConfigs = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
+		restConsumerServiceConfigMap[key] = rc
+	}
+
+	SetRestConsumerServiceConfigMap(restConsumerServiceConfigMap)
+
+	return nil
+}
+
+// initProviderRestConfig ...
+func initMethodConfigMap(rc *RestServiceConfig, consumes string, produces string) map[string]*RestMethodConfig {
+	mcm := make(map[string]*RestMethodConfig, len(rc.RestMethodConfigs))
+	for _, mc := range rc.RestMethodConfigs {
+		mc.InterfaceName = rc.InterfaceName
+		mc.Path = rc.Path + mc.Path
+		mc.Consumes = common.GetNotEmptyStr(mc.Consumes, rc.Consumes, consumes)
+		mc.Produces = common.GetNotEmptyStr(mc.Produces, rc.Produces, produces)
+		mc.MethodType = common.GetNotEmptyStr(mc.MethodType, rc.MethodType)
+		mc = transformMethodConfig(mc)
+		mcm[mc.MethodName] = mc
+	}
+	return mcm
+}
+
+// transformMethodConfig
+func transformMethodConfig(methodConfig *RestMethodConfig) *RestMethodConfig {

Review Comment:
   Gotcha!



-- 
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


[GitHub] [dubbo-go] justxuewei commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
justxuewei commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r884806048


##########
protocol/rest/config/common.go:
##########
@@ -0,0 +1,14 @@
+package config
+
+// function will return first not empty string ..
+// function will return first not empty string ..

Review Comment:
   duplicated two lines of comment



-- 
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


[GitHub] [dubbo-go] justxuewei commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
justxuewei commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r885136826


##########
config/router_config_test.go:
##########
@@ -55,14 +55,6 @@ func TestString(t *testing.T) {
 	assert.Equal(t, n2[1], "")
 }
 
-func TestRouterInit(t *testing.T) {
-	//err := RouterInit(testVirtualServiceYML, testDestinationRuleYML)
-	//assert.NoError(t, err)
-	//
-	//err = RouterInit(testVirtualServiceYML, errorTestDestinationRuleYML)
-	//assert.Error(t, err)
-}

Review Comment:
   Ok, if the unit test was moved to other place, please remove them from code.



-- 
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


[GitHub] [dubbo-go] sanxun0325 commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
sanxun0325 commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r882241522


##########
config/rest_config.go:
##########
@@ -32,6 +43,8 @@ type RestConsumerConfig struct {
 	Produces              string                        `default:"application/json" yaml:"rest_produces"  json:"rest_produces,omitempty" property:"rest_produces"`
 	Consumes              string                        `default:"application/json" yaml:"rest_consumes"  json:"rest_consumes,omitempty" property:"rest_consumes"`
 	RestServiceConfigsMap map[string]*RestServiceConfig `yaml:"references" json:"references,omitempty" property:"references"`
+

Review Comment:
   这个貌似没改?



-- 
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


[GitHub] [dubbo-go] complone commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
complone commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r856834997


##########
registry/nacos/listener.go:
##########
@@ -122,6 +122,7 @@ func generateUrl(instance model.Instance) *common.URL {
 	)
 }
 
+// 订阅注册中心地址的地方

Review Comment:
   好的 在下周前尽快处理



-- 
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


[GitHub] [dubbo-go] complone commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
complone commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r861678866


##########
protocol/rest/server/rest_server.go:
##########
@@ -32,9 +32,9 @@ import (
 import (
 	"dubbo.apache.org/dubbo-go/v3/common"
 	"dubbo.apache.org/dubbo-go/v3/common/logger"
+	rest_config "dubbo.apache.org/dubbo-go/v3/config"

Review Comment:
   have switched to rconfig



-- 
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


[GitHub] [dubbo-go] LaurenceLiZhixin commented on pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
LaurenceLiZhixin commented on PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#issuecomment-1112192024

   @complone 3.0 分支。


-- 
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


[GitHub] [dubbo-go] sanxun0325 commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
sanxun0325 commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r866873701


##########
config/rest_config.go:
##########
@@ -32,6 +43,8 @@ type RestConsumerConfig struct {
 	Produces              string                        `default:"application/json" yaml:"rest_produces"  json:"rest_produces,omitempty" property:"rest_produces"`
 	Consumes              string                        `default:"application/json" yaml:"rest_consumes"  json:"rest_consumes,omitempty" property:"rest_consumes"`
 	RestServiceConfigsMap map[string]*RestServiceConfig `yaml:"references" json:"references,omitempty" property:"references"`
+

Review Comment:
   空行可以删掉



##########
protocol/rest/config/reader/rest_config_reader.go:
##########
@@ -61,7 +61,8 @@ func (cr *RestConfigReader) ReadConsumerConfig(reader *bytes.Buffer) error {
 	restConsumerServiceConfigMap := make(map[string]*config.RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))
 	for key, rc := range restConsumerConfig.RestServiceConfigsMap {
 		rc.Client = getNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DefaultRestClient)
-		rc.RestMethodConfigsMap = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
+		//初始化每个方法的配置

Review Comment:
   用英文注释吧



##########
common/proxy/proxy.go:
##########
@@ -140,6 +140,7 @@ func DefaultProxyImplementFunc(p *Proxy, v common.RPCService) {
 				}
 			} else { // only return error
 				replyEmptyFlag = true
+				//reply = reflect.New(outs[0])

Review Comment:
   加一行注释的原因是?



##########
config/rest_config.go:
##########
@@ -92,6 +199,14 @@ func (c *RestServiceConfig) UnmarshalYAML(unmarshal func(interface{}) error) err
 	return nil
 }
 
+type RestCommonConfig struct {
+	Path           string `yaml:"path"  json:"rest_path,omitempty" property:"rest_path"`
+	MethodType     string `yaml:"method"  json:"rest_method,omitempty" property:"rest_method"`
+	QueryParams    string `yaml:"query_params"  json:"rest_query_params,omitempty" property:"rest_query_params"`
+	PathParams 	   string `yaml:"path_params" json:"rest_path_params,omitempty" property:"rest_query_params"`
+

Review Comment:
   空行



##########
config/config_resolver.go:
##########
@@ -52,6 +52,7 @@ func GetConfigResolver(conf *loaderConf) *koanf.Koanf {
 
 	switch conf.suffix {
 	case "yaml", "yml":
+		//err = k.Load(rawbytes.Provider(bytes), yaml.Parser())

Review Comment:
   同上



##########
config/rest_config.go:
##########
@@ -46,12 +59,107 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
 	return nil
 }
 
+// pi todo refactor
+func (c *RestConsumerConfig) Init(rc *RootConfig) error {
+	restConsumerConfig := rc.RestConsumer
+
+	if restConsumerConfig == nil {
+		logger.Debugf("[rest-protocol] no consumer config")
+		return nil
+	}
+
+	restConsumerServiceConfigMap := make(map[string]*RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))
+	for key, rc := range restConsumerConfig.RestServiceConfigsMap {
+		rc.Client = getNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DefaultRestClient)
+		rc.RestMethodConfigs = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
+		restConsumerServiceConfigMap[key] = rc
+	}
+
+	SetRestConsumerServiceConfigMap(restConsumerServiceConfigMap)
+
+	return nil
+}
+
+// initProviderRestConfig ...
+func initMethodConfigMap(rc *RestServiceConfig, consumes string, produces string) map[string]*RestMethodConfig {
+	mcm := make(map[string]*RestMethodConfig, len(rc.RestMethodConfigs))
+	for _, mc := range rc.RestMethodConfigs {
+		mc.InterfaceName = rc.InterfaceName
+		mc.Path = rc.Path + mc.Path
+		mc.Consumes = getNotEmptyStr(mc.Consumes, rc.Consumes, consumes)
+		mc.Produces = getNotEmptyStr(mc.Produces, rc.Produces, produces)
+		mc.MethodType = getNotEmptyStr(mc.MethodType, rc.MethodType)
+		mc = transformMethodConfig(mc)
+		mcm[mc.MethodName] = mc
+	}
+	return mcm
+}
+
+// transformMethodConfig
+func transformMethodConfig(methodConfig *RestMethodConfig) *RestMethodConfig {
+	if len(methodConfig.PathParamsMap) == 0 && len(methodConfig.PathParams) > 0 {
+		paramsMap, err := parseParamsString2Map(methodConfig.PathParams)
+		if err != nil {
+			logger.Warnf("[RestConfig] Path Param parse error:%v", err)
+		} else {
+			methodConfig.PathParamsMap = paramsMap
+		}
+	}
+	if len(methodConfig.QueryParamsMap) == 0 && len(methodConfig.QueryParams) > 0 {
+		paramsMap, err := parseParamsString2Map(methodConfig.QueryParams)
+		if err != nil {
+			logger.Warnf("[RestConfig] Query Param parse error:%v", err)
+		} else {
+			methodConfig.QueryParamsMap = paramsMap
+		}
+	}
+	if len(methodConfig.HeadersMap) == 0 && len(methodConfig.Headers) > 0 {
+		headersMap, err := parseParamsString2Map(methodConfig.Headers)
+		if err != nil {
+			logger.Warnf("[RestConfig] Header parse error:%v", err)
+		} else {
+			methodConfig.HeadersMap = headersMap
+		}
+	}
+	return methodConfig
+}
+
+// transform a string to a map
+// for example:
+// string "0:id,1:name" => map [0:id,1:name]
+func parseParamsString2Map(params string) (map[int]string, error) {
+	m := make(map[int]string, 8)
+	for _, p := range strings.Split(params, ",") {
+		pa := strings.Split(p, ":")
+		key, err := strconv.Atoi(pa[0])
+		if err != nil {
+			return nil, err
+		}
+		m[key] = pa[1]
+	}
+	return m, nil
+}
+
+// function will return first not empty string ..
+func getNotEmptyStr(args ...string) string {

Review Comment:
   getNotEmptyStr 这个func 在[rest_config_reader.go](https://github.com/apache/dubbo-go/pull/1855/files#diff-d33851599c1bda8da989a7716e0992742b67bd7c4a36113f0f0edfb181753110)已经有了,看起来是通用的,放在能共用的地方吧



##########
protocol/rest/config/reader/rest_config_reader.go:
##########
@@ -114,16 +115,26 @@ func getNotEmptyStr(args ...string) string {
 
 // transformMethodConfig
 func transformMethodConfig(methodConfig *config.RestMethodConfig) *config.RestMethodConfig {
-	if len(methodConfig.PathParamsMap) == 0 && len(methodConfig.PathParams) > 0 {
-		paramsMap, err := parseParamsString2Map(methodConfig.PathParams)
+	if len(methodConfig.PathParamsMap) == 0 && len(methodConfig.RestCommonConfig.PathParams) > 0 {

Review Comment:
   methodConfig.RestCommonConfig 我看在下面判断了是否等于nil, 在这里直接使用会出现nil情况么



##########
protocol/rest/server/rest_server.go:
##########
@@ -234,15 +237,18 @@ func assembleArgsFromBody(methodConfig *rest_config.RestMethodConfig, argsTypes
 			}
 		}
 		if err := req.ReadEntity(&ni); err != nil {
-			return perrors.Errorf("[Go restful] Read body entity error, error is %v", perrors.WithStack(err))
+			// pi todo improve the fault tolerance so just logger warn
+			//return perrors.Errorf("[Go restful] Read body entity error, error is %v", perrors.WithStack(err))

Review Comment:
   没用的注释和 todo 删掉吧



##########
protocol/rest/client/client_impl/resty_client.go:
##########
@@ -32,15 +32,12 @@ import (
 )
 
 import (
-	"dubbo.apache.org/dubbo-go/v3/common/constant"
-	"dubbo.apache.org/dubbo-go/v3/common/extension"
 	"dubbo.apache.org/dubbo-go/v3/protocol/rest/client"
 )
 
-func init() {
-	extension.SetRestClient(constant.DefaultRestClient, NewRestyClient)
-}
-
+//func init() {

Review Comment:
   注释的如果没用就直接删掉吧



##########
protocol/rest/rest_protocol.go:
##########
@@ -27,19 +27,33 @@ import (
 	"dubbo.apache.org/dubbo-go/v3/common/constant"
 	"dubbo.apache.org/dubbo-go/v3/common/extension"
 	"dubbo.apache.org/dubbo-go/v3/common/logger"
+	"dubbo.apache.org/dubbo-go/v3/config"
 	"dubbo.apache.org/dubbo-go/v3/protocol"
 	"dubbo.apache.org/dubbo-go/v3/protocol/rest/client"
-	_ "dubbo.apache.org/dubbo-go/v3/protocol/rest/client/client_impl"
-	rest_config "dubbo.apache.org/dubbo-go/v3/protocol/rest/config"
-	_ "dubbo.apache.org/dubbo-go/v3/protocol/rest/config/reader"
+	"dubbo.apache.org/dubbo-go/v3/protocol/rest/client/client_impl"
 	"dubbo.apache.org/dubbo-go/v3/protocol/rest/server"
-	_ "dubbo.apache.org/dubbo-go/v3/protocol/rest/server/server_impl"
 )
 
 var restProtocol *RestProtocol
 
 const REST = "rest"
 
+func init() {
+	SetRestServer(constant.DefaultRestServer, server.NewGoRestfulServer)
+}
+
+func init() {
+	extension.SetRestClient(constant.DefaultRestClient, client_impl.NewRestyClient)

Review Comment:
   多个init func合并到一个里面吧



-- 
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


[GitHub] [dubbo-go] justxuewei commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
justxuewei commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r885137373


##########
config/rest_config.go:
##########
@@ -46,12 +59,94 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
 	return nil
 }
 
+
+func (c *RestConsumerConfig) Init(rc *RootConfig) error {
+	restConsumerConfig := rc.RestConsumer
+
+	if restConsumerConfig == nil {
+		logger.Debugf("[rest-protocol] no consumer config")
+		return nil
+	}
+
+	restConsumerServiceConfigMap := make(map[string]*RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))
+	for key, rc := range restConsumerConfig.RestServiceConfigsMap {
+		rc.Client = common.GetNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DefaultRestClient)
+		rc.RestMethodConfigs = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
+		restConsumerServiceConfigMap[key] = rc
+	}
+
+	SetRestConsumerServiceConfigMap(restConsumerServiceConfigMap)
+
+	return nil
+}
+
+// initProviderRestConfig ...
+func initMethodConfigMap(rc *RestServiceConfig, consumes string, produces string) map[string]*RestMethodConfig {
+	mcm := make(map[string]*RestMethodConfig, len(rc.RestMethodConfigs))
+	for _, mc := range rc.RestMethodConfigs {
+		mc.InterfaceName = rc.InterfaceName
+		mc.Path = rc.Path + mc.Path
+		mc.Consumes = common.GetNotEmptyStr(mc.Consumes, rc.Consumes, consumes)
+		mc.Produces = common.GetNotEmptyStr(mc.Produces, rc.Produces, produces)
+		mc.MethodType = common.GetNotEmptyStr(mc.MethodType, rc.MethodType)
+		mc = transformMethodConfig(mc)
+		mcm[mc.MethodName] = mc
+	}
+	return mcm
+}
+
+// transformMethodConfig
+func transformMethodConfig(methodConfig *RestMethodConfig) *RestMethodConfig {

Review Comment:
   Yes, I am saying that the **return value** could be removed, cuz the type of the `methodConfig` on the parameter is a pointer.



-- 
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


[GitHub] [dubbo-go] justxuewei commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
justxuewei commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r884800423


##########
config/rest_config.go:
##########
@@ -46,12 +59,94 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
 	return nil
 }
 
+
+func (c *RestConsumerConfig) Init(rc *RootConfig) error {
+	restConsumerConfig := rc.RestConsumer
+
+	if restConsumerConfig == nil {
+		logger.Debugf("[rest-protocol] no consumer config")
+		return nil
+	}
+
+	restConsumerServiceConfigMap := make(map[string]*RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))

Review Comment:
   Please fix this lint problem.



-- 
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


[GitHub] [dubbo-go] LaurenceLiZhixin commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
LaurenceLiZhixin commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r885157132


##########
protocol/rest/rest_invoker_test.go:
##########
@@ -1,217 +1,217 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one or more

Review Comment:
   This header changes caust ci verify failed.
   And after you fix it, run `golangci-lint run` locally to make sure it pass, as I see , now your code have linter problems: https://github.com/apache/dubbo-go/runs/6663336503?check_suite_focus=true
   @complone 



##########
protocol/rest/rest_invoker_test.go:
##########
@@ -1,217 +1,217 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one or more

Review Comment:
   This header changes cause ci verify failed.
   And after you fix it, run `golangci-lint run` locally to make sure it pass, as I see , now your code have linter problems: https://github.com/apache/dubbo-go/runs/6663336503?check_suite_focus=true
   @complone 



-- 
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


[GitHub] [dubbo-go] pherzheyu commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
pherzheyu commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r856302228


##########
registry/nacos/listener.go:
##########
@@ -122,6 +122,7 @@ func generateUrl(instance model.Instance) *common.URL {
 	)
 }
 
+// 订阅注册中心地址的地方

Review Comment:
   能否规范下文档呢?



-- 
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


[GitHub] [dubbo-go] LaurenceLiZhixin commented on pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
LaurenceLiZhixin commented on PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#issuecomment-1126057708

   ping @complone 


-- 
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


[GitHub] [dubbo-go] complone commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
complone commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r885192894


##########
config/rest_config.go:
##########
@@ -46,12 +59,94 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
 	return nil
 }
 
+
+func (c *RestConsumerConfig) Init(rc *RootConfig) error {
+	restConsumerConfig := rc.RestConsumer
+
+	if restConsumerConfig == nil {
+		logger.Debugf("[rest-protocol] no consumer config")
+		return nil
+	}
+
+	restConsumerServiceConfigMap := make(map[string]*RestServiceConfig, len(restConsumerConfig.RestServiceConfigsMap))
+	for key, rc := range restConsumerConfig.RestServiceConfigsMap {
+		rc.Client = common.GetNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DefaultRestClient)
+		rc.RestMethodConfigs = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
+		restConsumerServiceConfigMap[key] = rc
+	}
+
+	SetRestConsumerServiceConfigMap(restConsumerServiceConfigMap)
+
+	return nil
+}
+
+// initProviderRestConfig ...
+func initMethodConfigMap(rc *RestServiceConfig, consumes string, produces string) map[string]*RestMethodConfig {
+	mcm := make(map[string]*RestMethodConfig, len(rc.RestMethodConfigs))
+	for _, mc := range rc.RestMethodConfigs {
+		mc.InterfaceName = rc.InterfaceName
+		mc.Path = rc.Path + mc.Path
+		mc.Consumes = common.GetNotEmptyStr(mc.Consumes, rc.Consumes, consumes)
+		mc.Produces = common.GetNotEmptyStr(mc.Produces, rc.Produces, produces)
+		mc.MethodType = common.GetNotEmptyStr(mc.MethodType, rc.MethodType)
+		mc = transformMethodConfig(mc)
+		mcm[mc.MethodName] = mc
+	}
+	return mcm
+}
+
+// transformMethodConfig
+func transformMethodConfig(methodConfig *RestMethodConfig) *RestMethodConfig {

Review Comment:
   The return value cannot be deleted because RestServiceConfig needs to declare the pointer type RestMethodConfigs map[string]*RestMethodConfig,  and the initMethodConfigMap method needs to obtain the converted config object



-- 
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


[GitHub] [dubbo-go] complone commented on a diff in pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
complone commented on code in PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#discussion_r885134599


##########
config/router_config_test.go:
##########
@@ -55,14 +55,6 @@ func TestString(t *testing.T) {
 	assert.Equal(t, n2[1], "")
 }
 
-func TestRouterInit(t *testing.T) {
-	//err := RouterInit(testVirtualServiceYML, testDestinationRuleYML)
-	//assert.NoError(t, err)
-	//
-	//err = RouterInit(testVirtualServiceYML, errorTestDestinationRuleYML)
-	//assert.Error(t, err)
-}

Review Comment:
   Deprecated because Router Init has been refactored to RouteConfig, unit tests are in router_config_test#TestNewRouterConfigBuilder



-- 
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


[GitHub] [dubbo-go] LaurenceLiZhixin commented on pull request #1855: feat: Rest protocol Support

Posted by GitBox <gi...@apache.org>.
LaurenceLiZhixin commented on PR #1855:
URL: https://github.com/apache/dubbo-go/pull/1855#issuecomment-1144878350

   After discussion, we merge this feature to a new branch rest-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.

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