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 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 ( // TODO: change this to ipv4.myip.dioad.net(A) ipv6.myip.dioad.net (AAAA) and myip.dioad.net(A and AAAA) // IPv4ICanHazIP is the URL to fetch the public IPv4 address. IPv4ICanHazIP = "http://ipv4.icanhazip.com" // IPv6ICanHazIP is the URL to fetch the public IPv6 address. IPv6ICanHazIP = "http://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 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
|
|
|
githubactions-oidc/client
command
|
|
|
githubactions-oidc/validator
command
|
|
|
ip-acl
command
|
|
|
oidc-auth
command
|
|
|
rate-limiting-dynamic
command
|
|
|
rate-limiting-http
command
|
|
|
rate-limiting-network
command
|
|
|
tls-config
command
|
|
|
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. |
|
auth
Package auth provides HTTP authentication utilities and interfaces.
|
Package auth provides HTTP authentication utilities and interfaces. |
|
auth/basic
Package basic provides HTTP Basic authentication middleware and utilities.
|
Package basic provides HTTP Basic authentication middleware and utilities. |
|
auth/context
Package context provides utilities for managing authentication information in context.
|
Package context provides utilities for managing authentication information in context. |
|
auth/github
Package github provides GitHub-based authentication middleware.
|
Package github provides GitHub-based authentication middleware. |
|
auth/hmac
Package hmac provides HMAC-based authentication middleware.
|
Package hmac provides HMAC-based authentication middleware. |
|
auth/oidc
Package oidc provides HTTP authentication using OpenID Connect.
|
Package oidc provides HTTP authentication using OpenID Connect. |
|
authz/ip
Package ip provides IP-based authorization middleware.
|
Package ip provides IP-based authorization middleware. |
|
authz/principal
Package principal provides principal-based authorization middleware.
|
Package principal provides principal-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. |
|
Package metrics provides utilities for tracking network connection and listener metrics.
|
Package metrics provides utilities for tracking network connection and listener metrics. |
|
Package oidc provides an OpenID Connect (OIDC) client and utilities for token validation and management.
|
Package oidc provides an OpenID Connect (OIDC) client and utilities for token validation and management. |
|
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. |
|
Package tls provides utilities for working with TLS certificates and configurations.
|
Package tls provides utilities for working with TLS certificates and configurations. |