refactor: 移除二维码和交叉编译,改为列出所有 LAN IP 地址;清理依赖

This commit is contained in:
2026-03-01 04:45:27 +08:00
parent 5d17e2e9ac
commit 2dbc916652
6 changed files with 34 additions and 83 deletions

View File

@@ -5,17 +5,21 @@ import (
"net"
)
// GetLANIP returns the first non-loopback IPv4 address.
func GetLANIP() (string, error) {
// GetLANIPs returns all non-loopback IPv4 addresses.
func GetLANIPs() ([]string, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "", err
return nil, err
}
var ips []string
for _, addr := range addrs {
if ipNet, ok := addr.(*net.IPNet); ok && !ipNet.IP.IsLoopback() && ipNet.IP.To4() != nil {
return ipNet.IP.String(), nil
ips = append(ips, ipNet.IP.String())
}
}
return "", fmt.Errorf("no LAN IP found")
if len(ips) == 0 {
return nil, fmt.Errorf("no LAN IP found")
}
return ips, nil
}