Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix ip is IsUnspecified #112

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion consul/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func parseAddr(addr net.Addr) (host string, port int, err error) {
return "", 0, fmt.Errorf("calling net.SplitHostPort failed, addr: %s, err: %w", addr.String(), err)
}

if host == "" || host == "::" {
ip := net.ParseIP(host)
if ip == nil || ip.IsUnspecified() {
detectHost := utils.LocalIP()
if detectHost == utils.UNKNOWN_IP_ADDR {
return "", 0, fmt.Errorf("get local ip error")
Expand Down
3 changes: 2 additions & 1 deletion etcd/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ func (e *etcdRegistry) getAddressOfRegistration(info *registry.Info) (string, er
}

// if host is empty or "::", use local ipv4 address as host
if host == "" || host == "::" {
ip := net.ParseIP(host)
if ip == nil || ip.IsUnspecified() {
host, err = getLocalIPv4Host()
if err != nil {
return "", fmt.Errorf("parse registry info addr error: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion eureka/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ func (e *eurekaRegistry) eurekaInstance(info *registry.Info) (*fargo.Instance, e
if portStr == "" {
return nil, fmt.Errorf("registry info addr missing port")
}
if host == "" || host == "::" {
ip := net.ParseIP(host)
if ip == nil || ip.IsUnspecified() {
host = utils.LocalIP()
if host == utils.UNKNOWN_IP_ADDR {
return nil, fmt.Errorf("get local ip error")
Expand Down
6 changes: 4 additions & 2 deletions nacos/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func (n *nacosRegistry) Register(info *registry.Info) error {
if err != nil {
return fmt.Errorf("parse registry info port error: %w", err)
}
if host == "" || host == "::" {
ip := net.ParseIP(host)
if ip == nil || ip.IsUnspecified() {
host = utils.LocalIP()
}
success, err := n.client.RegisterInstance(vo.RegisterInstanceParam{
Expand Down Expand Up @@ -121,7 +122,8 @@ func (n *nacosRegistry) Deregister(info *registry.Info) error {
if err != nil {
return fmt.Errorf("parse registry info port error: %w", err)
}
if host == "" || host == "::" {
ip := net.ParseIP(host)
if ip == nil || ip.IsUnspecified() {
host = utils.LocalIP()
}
success, err := n.client.DeregisterInstance(vo.DeregisterInstanceParam{
Expand Down
6 changes: 4 additions & 2 deletions nacos/v2/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func (n *nacosRegistry) Register(info *registry.Info) error {
if err != nil {
return fmt.Errorf("parse registry info port error: %w", err)
}
if host == "" || host == "::" {
ip := net.ParseIP(host)
if ip == nil || ip.IsUnspecified() {
host = utils.LocalIP()
}
success, err := n.client.RegisterInstance(vo.RegisterInstanceParam{
Expand Down Expand Up @@ -106,7 +107,8 @@ func (n *nacosRegistry) Deregister(info *registry.Info) error {
if err != nil {
return fmt.Errorf("parse registry info port error: %w", err)
}
if host == "" || host == "::" {
ip := net.ParseIP(host)
if ip == nil || ip.IsUnspecified() {
host = utils.LocalIP()
}
success, err := n.client.DeregisterInstance(vo.DeregisterInstanceParam{
Expand Down
3 changes: 2 additions & 1 deletion polaris/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func GetInfoHostAndPort(Addr string) (string, int, error) {
if port == "" {
return infoHost, 0, fmt.Errorf("registry info addr missing port")
}
if infoHost == "" || infoHost == "::" {
ip := net.ParseIP(infoHost)
if ip == nil || ip.IsUnspecified() {
infoHost = utils.LocalIP()
if infoHost == utils.UNKNOWN_IP_ADDR {
return "", 0, fmt.Errorf("get local ip error")
Expand Down
3 changes: 2 additions & 1 deletion servicecomb/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ func (scr *serviceCombRegistry) parseAddr(s string) (string, error) {
if err != nil {
return "", fmt.Errorf("parse addr error: %w", err)
}
if host == "" || host == "::" {
ip := net.ParseIP(host)
if ip == nil || ip.IsUnspecified() {
host = utils.LocalIP()
if host == utils.UNKNOWN_IP_ADDR {
return "", errors.New("get local ip error")
Expand Down
3 changes: 2 additions & 1 deletion zookeeper/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ func buildPath(info *registry.Info) (string, error) {
if port == "" {
return "", fmt.Errorf("registry info addr missing port")
}
if host == "" || host == "::" {
ip := net.ParseIP(host)
if ip == nil || ip.IsUnspecified() {
host = utils.LocalIP()
}
path = path + Separator + net.JoinHostPort(host, port)
Expand Down
Loading