Documentation
¶
Overview ¶
Package net provides production-ready networking utilities, authentication, authorization, and security features.
Index ¶
- Variables
- func AddrPortDetailsFromString(addrPort string) (netip.AddrPort, string, error)
- func ConvertAddrToIP(addr netip.Addr) net.IP
- func ExpandStringTemplate(templateString string, data any) (string, error)
- func FindInterfaceForAddr(a netip.Addr) (string, error)
- func FindInterfaceForIP(ip net.IP) (string, error)
- func FindTCPConn(c RawConn) *net.TCPConn
- func GetMyIPs(ctx context.Context) ([]netip.Addr, error)
- func GetMyIPsFromFuncs(ctx context.Context, funcs ...GetIPFunc) ([]netip.Addr, error)
- func GetMyIPv4(ctx context.Context) (netip.Addr, error)
- func GetMyIPv6(ctx context.Context) (netip.Addr, error)
- func IsBenignConnCloseError(err error) bool
- func TCPAddrFromURL(url *url.URL) (string, error)
- func TCPPortFromURL(url *url.URL) (string, error)
- type DoneConn
- type GetIPFunc
- type RawConn
Constants ¶
This section is empty.
Variables ¶
var ( // IPv4ICanHazIP is the URL to fetch the public IPv4 address. // TODO: change this to ipv4.myip.dioad.net(A) ipv6.myip.dioad.net (AAAA) and myip.dioad.net(A and AAAA). IPv4ICanHazIP = "https://ipv4.icanhazip.com" // IPv6ICanHazIP is the URL to fetch the public IPv6 address. IPv6ICanHazIP = "https://ipv6.icanhazip.com" )
Functions ¶
func AddrPortDetailsFromString ¶
AddrPortDetailsFromString takes a string representation of an address:port combination and returns the parsed netip.AddrPort, the network interface name that contains this address, and any error encountered during parsing or interface lookup. The input string should be in the format "IP:port" (e.g., "192.168.1.1:8080" or "[::1]:80"). Returns an empty AddrPort and empty string if an error occurs.
func ConvertAddrToIP ¶
ConvertAddrToIP converts a netip.Addr to a net.IP.
func ExpandStringTemplate ¶
ExpandStringTemplate expands a template string with the provided data.
func FindInterfaceForAddr ¶
FindInterfaceForAddr returns the network interface name that contains the given address.
func FindInterfaceForIP ¶
FindInterfaceForIP returns the network interface name that contains the given IP address.
func FindTCPConn ¶ added in v0.46.0
FindTCPConn recursively finds and returns the underlying *net.TCPConn from a RawConn.
func GetMyIPsFromFuncs ¶ added in v0.45.3
GetMyIPsFromFuncs fetches the public IP addresses using the provided functions.
func IsBenignConnCloseError ¶ added in v0.61.1
IsBenignConnCloseError reports whether err is an expected error from closing a net.Conn that does not indicate a server or infrastructure fault:
- net.ErrClosed: the connection was already closed before Close was called.
- TLS close_notify failure where the underlying connection was already gone.
Add new cases here as further benign close-error patterns are identified.
func TCPAddrFromURL ¶
TCPAddrFromURL returns a TCP address in the form of "host:port" from a given URL.
Types ¶
type DoneConn ¶ added in v0.44.0
DoneConn is a connection wrapper that provides a channel that is closed when the connection is closed.
func NewConnWithCloser ¶
NewConnWithCloser wraps a net.Conn with a function that is called when the connection is closed.
func NewDoneConn ¶ added in v0.44.0
NewDoneConn creates a new DoneConn wrapping the provided net.Conn.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package authz provides network-based and principal-based access control utilities.
|
Package authz provides network-based and principal-based access control utilities. |
|
prefixlist
Package prefixlist provides utilities for fetching and managing IP prefix lists from various cloud providers.
|
Package prefixlist provides utilities for fetching and managing IP prefix lists from various cloud providers. |
|
Package dns provides DNS-related utilities, including DNS-over-HTTPS and IP reverse lookups.
|
Package dns provides DNS-related utilities, including DNS-over-HTTPS and IP reverse lookups. |
|
examples
|
|
|
basic-http-server
command
Package main demonstrates a minimal HTTP server built with dioad/net/http.
|
Package main demonstrates a minimal HTTP server built with dioad/net/http. |
|
ip-acl
command
Package main demonstrates IP-based access control: authorizing individual requests against a network ACL and wrapping a net.Listener so that only connections from allowed IPs are accepted.
|
Package main demonstrates IP-based access control: authorizing individual requests against a network ACL and wrapping a net.Listener so that only connections from allowed IPs are accepted. |
|
rate-limiting-dynamic
command
Package main demonstrates rate limiting an HTTP server with limits supplied dynamically by a custom RateLimitSource.
|
Package main demonstrates rate limiting an HTTP server with limits supplied dynamically by a custom RateLimitSource. |
|
rate-limiting-http
command
Package main demonstrates rate limiting an HTTP server with static, per-principal limits.
|
Package main demonstrates rate limiting an HTTP server with static, per-principal limits. |
|
rate-limiting-network
command
Package main demonstrates rate limiting a raw TCP listener by source IP using ratelimit.Listener.
|
Package main demonstrates rate limiting a raw TCP listener by source IP using ratelimit.Listener. |
|
tls-config
command
Package main demonstrates configuring an HTTPS server with a self-signed TLS certificate.
|
Package main demonstrates configuring an HTTPS server with a self-signed TLS certificate. |
|
Package http provides an HTTP server and client with built-in support for metrics, authentication, and structured logging.
|
Package http provides an HTTP server and client with built-in support for metrics, authentication, and structured logging. |
|
authz/ip
Package ip provides IP-based authorization middleware.
|
Package ip provides IP-based authorization middleware. |
|
json
Package json provides utilities for handling JSON requests and responses.
|
Package json provides utilities for handling JSON requests and responses. |
|
pprof
Package pprof provides an HTTP resource for exposing pprof debugging endpoints.
|
Package pprof provides an HTTP resource for exposing pprof debugging endpoints. |
|
resource
Package resource provides HTTP resources for wiring into a dioad/net/http server (e.g.
|
Package resource provides HTTP resources for wiring into a dioad/net/http server (e.g. |
|
Package httpcache provides a generic caching HTTP fetcher.
|
Package httpcache provides a generic caching HTTP fetcher. |
|
Package metrics provides utilities for tracking network connection and listener metrics.
|
Package metrics provides utilities for tracking network connection and listener metrics. |
|
Package ratelimit provides per-principal, token-bucket rate limiting for network listeners and HTTP handlers, with optional dynamic limits from an external RateLimitSource.
|
Package ratelimit provides per-principal, token-bucket rate limiting for network listeners and HTTP handlers, with optional dynamic limits from an external RateLimitSource. |
|
Package smtp aggregates the DNS records used for SMTP domain authentication and reporting (SPF, DKIM, DMARC, MTA-STS, TLSRPT).
|
Package smtp aggregates the DNS records used for SMTP domain authentication and reporting (SPF, DKIM, DMARC, MTA-STS, TLSRPT). |
|
dkim
Package dkim provides utilities for working with DKIM (DomainKeys Identified Mail) records.
|
Package dkim provides utilities for working with DKIM (DomainKeys Identified Mail) records. |
|
dmarc
Package dmarc provides types for building a DMARC DNS TXT record.
|
Package dmarc provides types for building a DMARC DNS TXT record. |
|
internal/txtchunk
Package txtchunk renders DNS TXT record values as zone-file text.
|
Package txtchunk renders DNS TXT record values as zone-file text. |
|
mtasts
Package mtasts provides types for building and serving an MTA-STS policy.
|
Package mtasts provides types for building and serving an MTA-STS policy. |
|
mx
Package mx provides a DNS MX record type for use with connect tunnels.
|
Package mx provides a DNS MX record type for use with connect tunnels. |
|
spf
Package spf provides types for building an SPF DNS TXT record.
|
Package spf provides types for building an SPF DNS TXT record. |
|
tlsrpt
Package tlsrpt provides types for building a TLSRPT (SMTP TLS Reporting) DNS TXT record.
|
Package tlsrpt provides types for building a TLSRPT (SMTP TLS Reporting) DNS TXT record. |
|
Package tls provides utilities for working with TLS certificates and configurations.
|
Package tls provides utilities for working with TLS certificates and configurations. |