package znet
import "zgo.at/zstd/znet"
Package znet contains utilities for network communication.
Index ¶
- func PrivateIP(addr net.IP) bool
- func PrivateIPString(ip string) bool
- func RemovePort(host string) string
- func SafeDialer(allowedNets []string, allowedPorts []int) *net.Dialer
Functions ¶
func PrivateIP ¶
PrivateIP reports if this is a private non-public IP address.
func PrivateIPString ¶
PrivateIPString reports if this is a private non-public IP address.
This will return true for anything that is not an IP address, such as "example.com" or "localhost".
func RemovePort ¶
RemovePort removes the "port" part of an hostname.
This only works for "host:port", and not URLs. See net.SplitHostPort.
func SafeDialer ¶
SafeDialer is only alllowed to connect to the listed networks and ports on non-private addresses.
Any attempt to connect to e.g. "127.0.0.1" will return an error. This is intended for clients that should only connect to external resources from user input.
If the allowed lists are empty then "tcp4", "tcp6", "80", and "443" are used.
The Timeout and KeepAlive are set to 30 seconds.
Also see zhttputil.SafeTransport() and zhttputil.SafeClient().
Source Files ¶
znet.go
- Version
- v0.0.0-20240930202209-a63c3335042a (latest)
- Published
- Sep 30, 2024
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 2 days ago –
Tools for package owners.