mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(host): align launcher and gateway host normalization semantics
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user