mirror of
https://gitee.com/johng/gf
synced 2026-07-04 04:52:48 +08:00
fix file registry that not works on windows (#2605)
This commit is contained in:
@ -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.
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -129,8 +129,8 @@ const (
|
||||
MDWeight = `weight`
|
||||
DefaultProtocol = `http`
|
||||
DefaultSeparator = "/"
|
||||
EndpointHostPortDelimiter = ":"
|
||||
defaultTimeout = 5 * time.Second
|
||||
endpointHostPortDelimiter = ":"
|
||||
endpointsDelimiter = ","
|
||||
)
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user