Skip to content
Snippets Groups Projects
Commit c7a0f593 authored by Patrick's avatar Patrick
Browse files

change service key to path key

parent 354e6634
No related branches found
No related tags found
No related merge requests found
......@@ -51,10 +51,10 @@ func initConsumerRestConfig() {
return
}
restConsumerServiceConfigMap = make(map[string]*rest_interface.RestConfig, len(restConsumerConfig.RestConfigMap))
for _, rc := range restConsumerConfig.RestConfigMap {
for key, rc := range restConsumerConfig.RestConfigMap {
rc.Client = getNotEmptyStr(rc.Client, restConsumerConfig.Client, constant.DEFAULT_REST_CLIENT)
rc.RestMethodConfigsMap = initMethodConfigMap(rc, restConsumerConfig.Consumes, restConsumerConfig.Produces)
restConsumerServiceConfigMap[rc.InterfaceName] = rc
restConsumerServiceConfigMap[strings.TrimPrefix(key, "/")] = rc
}
}
......@@ -66,10 +66,10 @@ func initProviderRestConfig() {
return
}
restProviderServiceConfigMap = make(map[string]*rest_interface.RestConfig, len(restProviderConfig.RestConfigMap))
for _, rc := range restProviderConfig.RestConfigMap {
for key, rc := range restProviderConfig.RestConfigMap {
rc.Server = getNotEmptyStr(rc.Server, restProviderConfig.Server, constant.DEFAULT_REST_SERVER)
rc.RestMethodConfigsMap = initMethodConfigMap(rc, restProviderConfig.Consumes, restProviderConfig.Produces)
restProviderServiceConfigMap[rc.InterfaceName] = rc
restProviderServiceConfigMap[strings.TrimPrefix(key, "/")] = rc
}
}
......@@ -139,12 +139,12 @@ func parseParamsString2Map(params string) (map[int]string, error) {
return m, nil
}
func GetRestConsumerServiceConfig(service string) *rest_interface.RestConfig {
return restConsumerServiceConfigMap[service]
func GetRestConsumerServiceConfig(path string) *rest_interface.RestConfig {
return restConsumerServiceConfigMap[path]
}
func GetRestProviderServiceConfig(service string) *rest_interface.RestConfig {
return restProviderServiceConfigMap[service]
func GetRestProviderServiceConfig(path string) *rest_interface.RestConfig {
return restProviderServiceConfigMap[path]
}
func SetRestConsumerServiceConfigMap(configMap map[string]*rest_interface.RestConfig) {
......
......@@ -31,7 +31,7 @@ func TestGetRestConsumerServiceConfig(t *testing.T) {
err := os.Setenv(constant.CONF_CONSUMER_FILE_PATH, "./rest_config_reader/testdata/consumer_config.yml")
assert.NoError(t, err)
initConsumerRestConfig()
serviceConfig := GetRestConsumerServiceConfig("com.ikurento.user.UserProvider")
serviceConfig := GetRestConsumerServiceConfig("UserProvider")
assert.NotEmpty(t, serviceConfig)
}
......@@ -39,6 +39,6 @@ func TestGetRestProviderServiceConfig(t *testing.T) {
err := os.Setenv(constant.CONF_PROVIDER_FILE_PATH, "./rest_config_reader/testdata/provider_config.yml")
assert.NoError(t, err)
initProviderRestConfig()
serviceConfig := GetRestProviderServiceConfig("com.ikurento.user.UserProvider")
serviceConfig := GetRestProviderServiceConfig("UserProvider")
assert.NotEmpty(t, serviceConfig)
}
......@@ -61,9 +61,9 @@ func NewRestProtocol() *RestProtocol {
func (rp *RestProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
url := invoker.GetUrl()
serviceKey := strings.TrimPrefix(url.Path, "/")
serviceKey := url.ServiceKey()
exporter := NewRestExporter(serviceKey, invoker, rp.ExporterMap())
restConfig := GetRestProviderServiceConfig(url.Service())
restConfig := GetRestProviderServiceConfig(strings.TrimPrefix(url.Path, "/"))
rp.SetExporterMap(serviceKey, exporter)
restServer := rp.getServer(url, restConfig)
restServer.Deploy(invoker, restConfig.RestMethodConfigsMap)
......@@ -78,7 +78,7 @@ func (rp *RestProtocol) Refer(url common.URL) protocol.Invoker {
if t, err := time.ParseDuration(requestTimeoutStr); err == nil {
requestTimeout = t
}
restConfig := GetRestConsumerServiceConfig(url.Service())
restConfig := GetRestConsumerServiceConfig(strings.TrimPrefix(url.Path, "/"))
restOptions := rest_interface.RestOptions{RequestTimeout: requestTimeout, ConnectTimeout: connectTimeout}
restClient := rp.getClient(restOptions, restConfig)
invoker := NewRestInvoker(url, &restClient, restConfig.RestMethodConfigsMap)
......
......@@ -70,7 +70,7 @@ func TestRestProtocol_Refer(t *testing.T) {
assert.Equal(t, 0, invokersLen)
}
func TestJsonrpcProtocol_Export(t *testing.T) {
func TestRestProtocol_Export(t *testing.T) {
// Export
proto := GetRestProtocol()
url, err := common.NewURL(context.Background(), "rest://127.0.0.1:8888/com.ikurento.user.UserProvider?anyhost=true&"+
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment