fix(host): align launcher and gateway host normalization semantics

This commit is contained in:
lc6464
2026-04-13 21:33:22 +08:00
parent 4e977367c2
commit 448027c02a
11 changed files with 380 additions and 22 deletions
+30 -2
View File
@@ -54,8 +54,8 @@ func FindPicoclawBinary() string {
return "picoclaw"
}
// GetLocalIP returns the local IP address of the machine.
func GetLocalIP() string {
// GetLocalIPv4 returns a non-loopback local IPv4 address.
func GetLocalIPv4() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return ""
@@ -68,6 +68,34 @@ func GetLocalIP() string {
return ""
}
// GetLocalIPv6 returns a non-loopback local IPv6 address.
func GetLocalIPv6() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return ""
}
for _, a := range addrs {
ipnet, ok := a.(*net.IPNet)
if !ok || ipnet.IP == nil {
continue
}
ip := ipnet.IP
if ip.IsLoopback() || ip.To4() != nil {
continue
}
if ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() {
continue
}
return ip.String()
}
return ""
}
// GetLocalIP returns a non-loopback local IPv4 address for backward compatibility.
func GetLocalIP() string {
return GetLocalIPv4()
}
// OpenBrowser automatically opens the given URL in the default browser.
func OpenBrowser(url string) error {
switch runtime.GOOS {