fix file registry that not works on windows (#2605)

This commit is contained in:
Starccck
2023-04-27 11:34:54 +08:00
committed by GitHub
parent 4c6ebe7808
commit c6b9b4d326
5 changed files with 10 additions and 6 deletions

View File

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

View File

@ -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)
}

View File

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

View File

@ -129,8 +129,8 @@ const (
MDWeight = `weight`
DefaultProtocol = `http`
DefaultSeparator = "/"
EndpointHostPortDelimiter = ":"
defaultTimeout = 5 * time.Second
endpointHostPortDelimiter = ":"
endpointsDelimiter = ","
)

View File

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