Supplementary Go networking libraries providing additional networking protocols and utilities
Supplementary Go networking libraries providing additional networking protocols, utilities, and low-level networking capabilities beyond the standard library. This package collection includes implementations for HTTP/2, QUIC, WebSocket, WebDAV, HTML parsing, DNS message handling, ICMP, IPv4/IPv6 socket options, proxy detection, internationalized domain names, and various networking utilities.
go get golang.org/x/net@v0.47.0// DNS message parsing
import "golang.org/x/net/dns/dnsmessage"
// HTML parsing and tokenization
import "golang.org/x/net/html"
import "golang.org/x/net/html/atom"
import "golang.org/x/net/html/charset"
// HTTP/2 support
import "golang.org/x/net/http2"
import "golang.org/x/net/http2/h2c"
import "golang.org/x/net/http2/hpack"
// Low-level networking protocols
import "golang.org/x/net/icmp"
import "golang.org/x/net/ipv4"
import "golang.org/x/net/ipv6"
// QUIC protocol
import "golang.org/x/net/quic"
// Web protocols
import "golang.org/x/net/webdav"
import "golang.org/x/net/websocket"
// Utilities
import "golang.org/x/net/proxy"
import "golang.org/x/net/publicsuffix"
import "golang.org/x/net/idna"
import "golang.org/x/net/netutil"import (
"fmt"
"golang.org/x/net/html"
"golang.org/x/net/idna"
"strings"
)
// Parse HTML content
func parseHTML() {
htmlContent := "<html><body><h1>Hello</h1></body></html>"
doc, err := html.Parse(strings.NewReader(htmlContent))
if err != nil {
panic(err)
}
// Traverse and manipulate the document tree
fmt.Println(doc.Type) // html.DocumentNode
}
// Convert internationalized domain names
func convertDomain() {
// Convert Unicode domain to ASCII (Punycode)
ascii, err := idna.ToASCII("münchen.de")
if err != nil {
panic(err)
}
fmt.Println(ascii) // "xn--mnchen-3ya.de"
// Convert back to Unicode
unicode, err := idna.ToUnicode("xn--mnchen-3ya.de")
if err != nil {
panic(err)
}
fmt.Println(unicode) // "münchen.de"
}DNS message parsing and building for custom DNS implementations.
// Build and parse DNS messages
type Message struct {
Header Header
Questions []Question
Answers []Resource
Authorities []Resource
Additionals []Resource
}
func (m *Message) Pack() ([]byte, error)
func (m *Message) Unpack(msg []byte) errorHTML5-compliant tokenization, parsing, and rendering with character set detection.
// Parse HTML documents
func Parse(r io.Reader) (*Node, error)
// Tokenize HTML
type Tokenizer struct { /* ... */ }
func NewTokenizer(r io.Reader) *Tokenizer
func (z *Tokenizer) Next() TokenType
// Render HTML
func Render(w io.Writer, n *Node) errorHTML Parsing and Tokenization HTML Atom Constants HTML Character Set Detection
Full HTTP/2 protocol implementation including cleartext (h2c) support and HPACK header compression.
// Configure HTTP/2 server
func ConfigureServer(s *http.Server, conf *Server) error
// Configure HTTP/2 transport
func ConfigureTransport(t1 *http.Transport) (*Transport, error)
// HTTP/2 server options
type Server struct {
MaxHandlers int
MaxConcurrentStreams uint32
MaxReadFrameSize uint32
PermitProhibitedCipherSuites bool
IdleTimeout time.Duration
// ...
}HTTP/2 Implementation HTTP/2 Cleartext (h2c) HPACK Header Compression HTTP Internals HTTP Proxy Configuration
ICMP protocol handling for ping and traceroute implementations.
// Create ICMP connection
func ListenPacket(network, address string) (*PacketConn, error)
// ICMP message structure
type Message struct {
Type Type
Code int
Checksum int
Body MessageBody
}
func (m *Message) Marshal(psh []byte) ([]byte, error)
func ParseMessage(proto int, b []byte) (*Message, error)Low-level IPv4 and IPv6 socket option control and packet manipulation.
// IPv4 packet connection
type PacketConn struct { /* ... */ }
func NewPacketConn(c net.PacketConn) *PacketConn
// IPv4 raw connection
type RawConn struct { /* ... */ }
func NewRawConn(c net.PacketConn) (*RawConn, error)
// Socket options
func (c *PacketConn) SetTOS(tos int) error
func (c *PacketConn) SetTTL(ttl int) errorIPv4 Socket Options IPv6 Socket Options
QUIC protocol implementation with logging support.
// QUIC connection
type Conn struct { /* ... */ }
// QUIC listener
func Listen(conn net.PacketConn, tlsConf *tls.Config, config *Config) (Listener, error)
// QUIC dialer
func Dial(pconn net.PacketConn, addr net.Addr, host string, tlsConf *tls.Config, config *Config) (Conn, error)WebDAV server/client and WebSocket protocol implementation.
// WebDAV handler
type Handler struct {
FileSystem FileSystem
LockSystem LockSystem
Logger func(*http.Request, error)
}
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
// WebSocket connection
type Conn struct { /* ... */ }
func Dial(url_, protocol, origin string) (ws *Conn, err error)WebDAV Server and Client WebSocket Protocol
Additional protocol implementations and utilities.
// Berkeley Packet Filter
type Instruction interface {
Assemble() (RawInstruction, error)
}
func Assemble(insts []Instruction) ([]RawInstruction, error)
// DICT protocol client
type Client struct { /* ... */ }
func Dial(network, addr string) (*Client, error)
// Proxy support
type Dialer interface {
Dial(network, addr string) (c net.Conn, err error)
}
func FromEnvironment() DialerBerkeley Packet Filter (BPF) DICT Protocol Client Proxy Support
Internationalized domain name support and public suffix list.
// IDNA conversion
func ToASCII(s string) (string, error)
func ToUnicode(s string) (string, error)
// Public suffix detection
func EffectiveTLDPlusOne(domain string) (string, error)
func PublicSuffix(domain string) (string, error)Internationalized Domain Names Public Suffix List
Network testing, utilities, tracing, and security.
// Limit concurrent connections
func LimitListener(l net.Listener, n int) net.Listener
// Test network interfaces
func SupportsIPv4() bool
func SupportsIPv6() bool
// Request tracing
type Trace struct { /* ... */ }
func New(family, title string) Trace
// XSRF token generation
func Generate(key, userID, actionID string) string
func Valid(token, key, userID, actionID string) boolNetwork Utilities Network Testing Request Tracing XSRF Token Generation HTTP with Context Context Compatibility (Deprecated)
Install with Tessl CLI
npx tessl i tessl/golang-golang-org-x--netdocs