Initial import

This commit is contained in:
2025-09-26 08:49:53 +02:00
commit a76650da35
35 changed files with 4660 additions and 0 deletions

35
internal/netutil/addr.go Normal file
View File

@@ -0,0 +1,35 @@
package netutil
import (
"net"
"strconv"
)
// EnsurePort makes sure the address in [host] contains a port.
func EnsurePort(host, port string) string {
if _, _, err := net.SplitHostPort(host); err == nil {
return host
}
return net.JoinHostPort(host, port)
}
// Host returns the bare host (without port).
func Host(name string) string {
host, _, err := net.SplitHostPort(name)
if err == nil {
return host
}
return name
}
// Port returns the port number.
func Port(name string) int {
_, port, err := net.SplitHostPort(name)
if err != nil {
return 0
}
// TODO: name resolution for ports?
i, _ := strconv.Atoi(port)
return i
}