Skip to content

Commit

Permalink
Fix nacos not support empty serverConfigs (#2691)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ authored Jun 28, 2024
1 parent d7a3502 commit e755697
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions remoting/nacos/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,28 @@ func GetNacosConfig(url *common.URL) ([]nacosConstant.ServerConfig, nacosConstan
perrors.New("url.location is empty!")
}

addresses := strings.Split(url.Location, ",")
serverConfigs := make([]nacosConstant.ServerConfig, 0, len(addresses))
for _, addr := range addresses {
ip, portStr, err := net.SplitHostPort(addr)
if err != nil {
return []nacosConstant.ServerConfig{}, nacosConstant.ClientConfig{},
perrors.WithMessagef(err, "split [%s] ", addr)
var serverConfigs []nacosConstant.ServerConfig
if len(url.Location) != 0 {
addresses := strings.Split(url.Location, ",")
serverConfigs = make([]nacosConstant.ServerConfig, 0, len(addresses))
for _, addr := range addresses {
ip, portStr, err := net.SplitHostPort(addr)
if err != nil {
return []nacosConstant.ServerConfig{}, nacosConstant.ClientConfig{},
perrors.WithMessagef(err, "split [%s] ", addr)
}
portContextPath := strings.Split(portStr, constant.PathSeparator)
port, err := strconv.Atoi(portContextPath[0])
if err != nil {
return []nacosConstant.ServerConfig{}, nacosConstant.ClientConfig{},
perrors.WithMessagef(err, "port [%s] ", portContextPath[0])
}
var contextPath string
if len(portContextPath) > 1 {
contextPath = constant.PathSeparator + strings.Join(portContextPath[1:], constant.PathSeparator)
}
serverConfigs = append(serverConfigs, nacosConstant.ServerConfig{IpAddr: ip, Port: uint64(port), ContextPath: contextPath})
}
portContextPath := strings.Split(portStr, constant.PathSeparator)
port, err := strconv.Atoi(portContextPath[0])
if err != nil {
return []nacosConstant.ServerConfig{}, nacosConstant.ClientConfig{},
perrors.WithMessagef(err, "port [%s] ", portContextPath[0])
}
var contextPath string
if len(portContextPath) > 1 {
contextPath = constant.PathSeparator + strings.Join(portContextPath[1:], constant.PathSeparator)
}
serverConfigs = append(serverConfigs, nacosConstant.ServerConfig{IpAddr: ip, Port: uint64(port), ContextPath: contextPath})
}

timeout := url.GetParamDuration(constant.NacosTimeout, constant.DefaultRegTimeout)
Expand Down

0 comments on commit e755697

Please sign in to comment.