refactor: project structure

This commit is contained in:
2026-05-21 21:13:14 +08:00
parent e60a1ef082
commit f2936ac6ad
8 changed files with 298 additions and 247 deletions

25
internal/filter/filter.go Normal file
View File

@@ -0,0 +1,25 @@
package filter
import (
"fmt"
"net"
)
// IP filters a list of resolved IPs and returns the first match
// for the requested address family (IPv4 or IPv6).
func IP(ips []net.IP, ipv6 bool) (string, error) {
if ipv6 {
for _, ip := range ips {
if ip.To16() != nil && ip.To4() == nil {
return ip.String(), nil
}
}
} else {
for _, ip := range ips {
if ip.To4() != nil && ip.To16() != nil {
return ip.String(), nil
}
}
}
return "", fmt.Errorf("no suitable IP address found")
}