Skip to content

Commit

Permalink
fix nacos weight <= 0 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-Morgan committed Sep 19, 2024
1 parent 23c28df commit 11f1826
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
7 changes: 6 additions & 1 deletion registry/nacos/nacoshertz/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ func (n *nacosRegistry) Register(info *registry.Info) error {
if host == "" || host == "::" {
host = utils.LocalIP()
}
// make sure nacos weight >= 0
weight := 1
if info.Weight >= 0 {
weight = info.Weight
}
success, err := n.client.RegisterInstance(vo.RegisterInstanceParam{
Ip: host,
Port: uint64(p),
ServiceName: info.ServiceName,
GroupName: n.opts.Group,
ClusterName: n.opts.Cluster,
Weight: float64(info.Weight),
Weight: float64(weight),
Enable: true,
Healthy: true,
Ephemeral: true,
Expand Down
7 changes: 6 additions & 1 deletion registry/nacos/nacoshertz/v2/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ func (n *nacosRegistry) Register(info *registry.Info) error {
if host == "" || host == "::" {
host = utils.LocalIP()
}
// make sure nacos weight >= 0
weight := 1
if info.Weight >= 0 {
weight = info.Weight
}
success, err := n.client.RegisterInstance(vo.RegisterInstanceParam{
Ip: host,
Port: uint64(p),
ServiceName: info.ServiceName,
GroupName: n.opts.Group,
ClusterName: n.opts.Cluster,
Weight: float64(info.Weight),
Weight: float64(weight),
Enable: true,
Ephemeral: true,
Healthy: true,
Expand Down
8 changes: 6 additions & 2 deletions registry/nacos/nacoskitex/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ func (n *nacosRegistry) Register(info *registry.Info) error {
return fmt.Errorf("parse registry info addr cwerror: %w", err)
}
}

// make sure nacos weight >= 0
weight := 1
if info.Weight >= 0 {
weight = info.Weight
}
_, e := n.cli.RegisterInstance(vo.RegisterInstanceParam{
Ip: host,
Port: uint64(p),
ServiceName: info.ServiceName,
Weight: float64(info.Weight),
Weight: float64(weight),
Enable: true,
Healthy: true,
Metadata: mergeTags(info.Tags, nacos.Tags),
Expand Down
8 changes: 6 additions & 2 deletions registry/nacos/nacoskitex/v2/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ func (n *nacosRegistry) Register(info *registry.Info) error {
return fmt.Errorf("parse registry info addr cwerror: %w", err)
}
}

// make sure nacos weight >= 0
weight := 1
if info.Weight >= 0 {
weight = info.Weight
}
_, e := n.cli.RegisterInstance(vo.RegisterInstanceParam{
Ip: host,
Port: uint64(p),
ServiceName: info.ServiceName,
Weight: float64(info.Weight),
Weight: float64(weight),
Enable: true,
Healthy: true,
Metadata: mergeTags(info.Tags, nacos.Tags),
Expand Down

0 comments on commit 11f1826

Please sign in to comment.