diff --git a/contrib/registry/file/file.go b/contrib/registry/file/file.go index aa20fd071..507bb78f7 100644 --- a/contrib/registry/file/file.go +++ b/contrib/registry/file/file.go @@ -19,10 +19,11 @@ var ( ) const ( - updateAtKey = "UpdateAt" - serviceTTL = 20 * time.Second - serviceUpdateInterval = 10 * time.Second - defaultSeparator = "#" + updateAtKey = "UpdateAt" + serviceTTL = 20 * time.Second + serviceUpdateInterval = 10 * time.Second + defaultSeparator = "#" + defaultEndpointHostPortDelimiter = "-" ) // Registry implements interface Registry using file. diff --git a/contrib/registry/file/file_discovery.go b/contrib/registry/file/file_discovery.go index a8cc028d1..e6b4560b3 100644 --- a/contrib/registry/file/file_discovery.go +++ b/contrib/registry/file/file_discovery.go @@ -108,6 +108,8 @@ func (r *Registry) getServiceByFilePath(filePath string) (gsvc.Service, error) { fileContent = gfile.GetContents(filePath) serviceKey = gstr.Replace(fileName, defaultSeparator, gsvc.DefaultSeparator) ) + + serviceKey = gstr.Replace(serviceKey, defaultEndpointHostPortDelimiter, gsvc.EndpointHostPortDelimiter) serviceKey = gsvc.DefaultSeparator + serviceKey return gsvc.NewServiceWithKV(serviceKey, fileContent) } diff --git a/contrib/registry/file/file_registrar.go b/contrib/registry/file/file_registrar.go index e9c4139b1..d98098779 100644 --- a/contrib/registry/file/file_registrar.go +++ b/contrib/registry/file/file_registrar.go @@ -58,5 +58,6 @@ func (r *Registry) getServiceFileName(service gsvc.Service) string { func (r *Registry) getServiceKeyForFile(key string) string { key = gstr.Replace(key, gsvc.DefaultSeparator, defaultSeparator) key = gstr.Trim(key, defaultSeparator) + key = gstr.Replace(key, gsvc.EndpointHostPortDelimiter, defaultEndpointHostPortDelimiter) return key } diff --git a/net/gsvc/gsvc.go b/net/gsvc/gsvc.go index e192c38da..34d0c0424 100644 --- a/net/gsvc/gsvc.go +++ b/net/gsvc/gsvc.go @@ -129,8 +129,8 @@ const ( MDWeight = `weight` DefaultProtocol = `http` DefaultSeparator = "/" + EndpointHostPortDelimiter = ":" defaultTimeout = 5 * time.Second - endpointHostPortDelimiter = ":" endpointsDelimiter = "," ) diff --git a/net/gsvc/gsvc_endpoint.go b/net/gsvc/gsvc_endpoint.go index f75e3fe3e..d4420614f 100644 --- a/net/gsvc/gsvc_endpoint.go +++ b/net/gsvc/gsvc_endpoint.go @@ -25,7 +25,7 @@ type LocalEndpoint struct { // NewEndpoint creates and returns an Endpoint from address string of pattern "host:port", // eg: "192.168.1.100:80". func NewEndpoint(address string) Endpoint { - array := gstr.SplitAndTrim(address, endpointHostPortDelimiter) + array := gstr.SplitAndTrim(address, EndpointHostPortDelimiter) if len(array) != 2 { panic(gerror.NewCodef( gcode.CodeInvalidParameter,