From c3db25d7b51c9f1fd4e0a383b17f1edccbb23240 Mon Sep 17 00:00:00 2001 From: Patrick <dreamlike.sky@foxmail.com> Date: Sun, 7 Feb 2021 15:47:42 +0800 Subject: [PATCH] replace id to path --- protocol/rest/config/reader/rest_config_reader.go | 4 ++-- protocol/rest/config/rest_config.go | 8 ++++---- protocol/rest/rest_protocol.go | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/protocol/rest/config/reader/rest_config_reader.go b/protocol/rest/config/reader/rest_config_reader.go index 873af9924..2338790ea 100644 --- a/protocol/rest/config/reader/rest_config_reader.go +++ b/protocol/rest/config/reader/rest_config_reader.go @@ -62,7 +62,7 @@ func (cr *RestConfigReader) ReadConsumerConfig(reader *bytes.Buffer) error { for key, rc := range restConsumerConfig.RestServiceConfigsMap { rc.Client = getNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DEFAULT_REST_CLIENT) rc.RestMethodConfigsMap = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces) - restConsumerServiceConfigMap[strings.TrimPrefix(key, "/")] = rc + restConsumerServiceConfigMap[key] = rc } config.SetRestConsumerServiceConfigMap(restConsumerServiceConfigMap) return nil @@ -79,7 +79,7 @@ func (cr *RestConfigReader) ReadProviderConfig(reader *bytes.Buffer) error { for key, rc := range restProviderConfig.RestServiceConfigsMap { rc.Server = getNotEmptyStr(rc.Server, restProviderConfig.Server, constant.DEFAULT_REST_SERVER) rc.RestMethodConfigsMap = initMethodConfigMap(rc, restProviderConfig.Consumes, restProviderConfig.Produces) - restProviderServiceConfigMap[strings.TrimPrefix(key, "/")] = rc + restProviderServiceConfigMap[key] = rc } config.SetRestProviderServiceConfigMap(restProviderServiceConfigMap) return nil diff --git a/protocol/rest/config/rest_config.go b/protocol/rest/config/rest_config.go index 4732dd8e4..27c67db12 100644 --- a/protocol/rest/config/rest_config.go +++ b/protocol/rest/config/rest_config.go @@ -123,13 +123,13 @@ func (c *RestMethodConfig) UnmarshalYAML(unmarshal func(interface{}) error) erro } // nolint -func GetRestConsumerServiceConfig(path string) *RestServiceConfig { - return restConsumerServiceConfigMap[path] +func GetRestConsumerServiceConfig(id string) *RestServiceConfig { + return restConsumerServiceConfigMap[id] } // nolint -func GetRestProviderServiceConfig(path string) *RestServiceConfig { - return restProviderServiceConfigMap[path] +func GetRestProviderServiceConfig(id string) *RestServiceConfig { + return restProviderServiceConfigMap[id] } // nolint diff --git a/protocol/rest/rest_protocol.go b/protocol/rest/rest_protocol.go index 05e119b05..d19bd002f 100644 --- a/protocol/rest/rest_protocol.go +++ b/protocol/rest/rest_protocol.go @@ -18,7 +18,6 @@ package rest import ( - "strings" "sync" "time" ) @@ -72,7 +71,8 @@ func (rp *RestProtocol) Export(invoker protocol.Invoker) protocol.Exporter { url := invoker.GetUrl() serviceKey := url.ServiceKey() exporter := NewRestExporter(serviceKey, invoker, rp.ExporterMap()) - restServiceConfig := rest_config.GetRestProviderServiceConfig(strings.TrimPrefix(url.Path, "/")) + id := url.GetParam(constant.BEAN_NAME_KEY, "") + restServiceConfig := rest_config.GetRestProviderServiceConfig(id) if restServiceConfig == nil { logger.Errorf("%s service doesn't has provider config", url.Path) return nil @@ -94,7 +94,8 @@ func (rp *RestProtocol) Refer(url *common.URL) protocol.Invoker { if t, err := time.ParseDuration(requestTimeoutStr); err == nil { requestTimeout = t } - restServiceConfig := rest_config.GetRestConsumerServiceConfig(strings.TrimPrefix(url.Path, "/")) + id := url.GetParam(constant.BEAN_NAME_KEY, "") + restServiceConfig := rest_config.GetRestConsumerServiceConfig(id) if restServiceConfig == nil { logger.Errorf("%s service doesn't has consumer config", url.Path) return nil -- GitLab