or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bpf.mdcontext-ctxhttp.mdcontext.mddict.mddns-dnsmessage.mdhtml-atom.mdhtml-charset.mdhtml.mdhttp-httpguts.mdhttp-httpproxy.mdhttp2-h2c.mdhttp2-hpack.mdhttp2.mdicmp.mdidna.mdindex.mdipv4.mdipv6.mdnettest.mdnetutil.mdproxy.mdpublicsuffix.mdquic-qlog.mdquic.mdtrace.mdwebdav.mdwebsocket.mdxsrftoken.md
tile.json

index.mddocs/

golang.org/x/net

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.

Package Information

  • Package Name: golang.org/x/net
  • Package Type: Go module
  • Language: Go
  • Installation: go get golang.org/x/net@v0.47.0

Core Imports

// 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"

Basic Usage

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"
}

Capabilities

DNS

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) error

DNS Message Handling

HTML

HTML5-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) error

HTML Parsing and Tokenization HTML Atom Constants HTML Character Set Detection

HTTP/2

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

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)

ICMP Protocol Handling

IPv4/IPv6

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) error

IPv4 Socket Options IPv6 Socket Options

QUIC

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)

QUIC Protocol QUIC Logging

Web

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

Protocols

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() Dialer

Berkeley Packet Filter (BPF) DICT Protocol Client Proxy Support

Internationalization

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

Utilities

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) bool

Network Utilities Network Testing Request Tracing XSRF Token Generation HTTP with Context Context Compatibility (Deprecated)