This commit is contained in:
2026-03-02 01:43:46 +07:00
parent 5604732fcb
commit 3b9c77b422
5 changed files with 55 additions and 50 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
package link
type ILinkService interface {
GetTeamClientLink(name string, password string) (string, error)
GetTeamClientLink(host string, name string, password string) string
}
+2 -39
View File
@@ -2,7 +2,6 @@ package link
import (
"fmt"
"net"
"net/url"
)
@@ -12,42 +11,6 @@ func NewLinkService() ILinkService {
return &service{}
}
func (s *service) GetTeamClientLink(name string, password string) (string, error) {
ip := selectIP()
u := fmt.Sprintf("http://%s:8100?name=%s&password=%s", ip, url.PathEscape(name), password)
return u, nil
}
func selectIP() string {
ips, err := getLocalIPs()
if err != nil || len(ips) == 0 {
return "127.0.0.1"
}
return ips[0]
}
func getLocalIPs() ([]string, error) {
var ips []string
addrs, err := net.InterfaceAddrs()
if err != nil {
return nil, err
}
for _, addr := range addrs {
ipNet, ok := addr.(*net.IPNet)
if !ok {
continue
}
ip := ipNet.IP
if ip.IsLoopback() || ip.IsLinkLocalMulticast() || ip.IsLinkLocalUnicast() {
continue
}
if ipv4 := ip.To4(); ipv4 != nil {
ips = append(ips, ipv4.String())
}
}
return ips, nil
func (s *service) GetTeamClientLink(host string, name string, password string) string {
return fmt.Sprintf("http://%s?name=%s&password=%s", host, url.PathEscape(name), password)
}