server

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 41 Imported by: 0

README

server godoc test Coverage Status Release License

Documentation

Index

Constants

View Source
const HTTP2_PREAMBLE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"

Variables

View Source
var ErrNotWebSocket = errors.New("server: connection does not support WebSocket upgrade")

ErrNotWebSocket is returned by UpgradeWebSocket when the underlying connection does not support the WebSocket upgrade.

View Source
var ErrNotWebTransport = errors.New("server: connection does not support WebTransport upgrade")

ErrNotWebTransport is returned by UpgradeWebTransport when the underlying connection does not support the WebTransport upgrade.

View Source
var (
	// RouteCtxKey is the context.Context key to store the request context.
	RouteCtxKey = &contextKey{"RouteContext"}
)
View Source
var Sessions = func(next Handler) Handler {
	return HandlerFunc(func(w ResponseWriter, r *Request) {

		session.GetRegistry(r.Request)
		next.ServeHTTP(w, r)
	})
}

Sessions is a middleware that attaches the request's session registry to the request context before any downstream middleware replaces the request, so session values survive r.WithContext reassignments across the middleware stack. It is optional: the typed GetSession/SaveSession helpers create the registry lazily when it is not already present.

Example:

r := server.NewRouter()
r.Use(server.Sessions)

store := session.NewCookieStore([]byte("auth-key"))

r.Get("/", func(w server.ResponseWriter, r *server.Request) {
	s, err := server.GetSession(r, store, "my-session")
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	defer server.SaveSession(r, w)
	s.Values["visits"] = ...
})

Functions

func GetSession

func GetSession(r *Request, store session.Store, name string) (*session.Session, error)

GetSession returns the session registered for the request under name from store, creating and registering it if needed. Repeated calls for the same name within one request return the same session instance.

It is a thin wrapper around Store.Get that works with the server's Request type; the underlying registry is stored on the request context.

func RegisterMethod

func RegisterMethod(method string)

RegisterMethod adds support for custom HTTP method handlers, available via Router#Method and Router#MethodFunc

func SaveSession

func SaveSession(r *Request, w ResponseWriter) error

SaveSession saves all sessions registered for the request, writing their cookies to w. It should be called before writing the response body or returning from the handler.

func SelfSigned

func SelfSigned(host string) ([]byte, []byte, error)

SelfSigned generates (or returns from cache) a self-signed certificate for the given host, covering both DNS names and IP addresses.

func ToHTTPHandler

func ToHTTPHandler(h Handler) http.Handler

ToHTTPHandler adapts a server Handler into a github.com/malivvan/http Handler, so it can be served by the fork's HTTP server and exercised with its httptest package. Requests and response writers coming from the fork are converted to server types; the wrapped writer's upgrade methods report ErrNotWebSocket / ErrNotWebTransport, since the fork's writer cannot perform the server's connection upgrades.

func URLParam

func URLParam(r *Request, key string) string

URLParam returns the url parameter from a Request object.

func URLParamFromCtx

func URLParamFromCtx(ctx context.Context, key string) string

URLParamFromCtx returns the url parameter from a request Context.

func Walk

func Walk(r Routes, walkFn WalkFunc) error

Walk walks any router tree that implements Routes interface.

Types

type ChainHandler

type ChainHandler struct {
	Endpoint Handler

	Middlewares Middlewares
	// contains filtered or unexported fields
}

ChainHandler is a Handler with support for handler composition and execution.

func (*ChainHandler) ServeHTTP

func (c *ChainHandler) ServeHTTP(w ResponseWriter, r *Request)

type Context

type Context struct {
	Routes Routes

	// Routing path/method override used during the route search.
	// See Mux#routeHTTP method.
	RoutePath   string
	RouteMethod string

	// URLParams are the stack of routeParams captured during the
	// routing lifecycle across a stack of sub-routers.
	URLParams RouteParams

	// Routing pattern stack throughout the lifecycle of the request,
	// across all connected routers. It is a record of all matching
	// patterns across a stack of sub-routers.
	RoutePatterns []string

	// Fingerprint holds the fingerprint details of the request being routed
	// (TLS, HTTP/1, HTTP/2, HTTP/3, TCP/IP). It is populated from
	// Request.Fingerprint when the routing context is created, so handlers
	// and middlewares can reach it via RouteContext(r.Context()).
	Fingerprint *fingerprint.Request
	// contains filtered or unexported fields
}

Context is the default routing context set on the root node of a request context to track route patterns, URL parameters and an optional routing path.

func NewRouteContext

func NewRouteContext() *Context

NewRouteContext returns a new routing Context object.

func RouteContext

func RouteContext(ctx context.Context) *Context

RouteContext returns chi's routing Context object from a Request Context.

func (*Context) Reset

func (x *Context) Reset()

Reset a routing context to its initial state.

func (*Context) RoutePattern

func (x *Context) RoutePattern() string

RoutePattern builds the routing pattern string for the particular request, at the particular point during routing. This means, the value will change throughout the execution of a request in a router. That is why it's advised to only use this value after calling the next handler.

For example,

func Instrument(next Handler) Handler {
	return HandlerFunc(func(w ResponseWriter, r *Request) {
		next.ServeHTTP(w, r)
		routePattern := server.RouteContext(r.Context()).RoutePattern()
		measure(w, r, routePattern)
	})
}

func (*Context) URLParam

func (x *Context) URLParam(key string) string

URLParam returns the corresponding URL parameter value from the request routing context.

type Handler

type Handler interface {
	ServeHTTP(ResponseWriter, *Request)
}

Handler responds to a server.Request. The ResponseWriter allows the handler to write a normal HTTP response or to upgrade the connection to WebSocket (HTTP/1) or WebTransport (HTTP/3).

func ToHandler

func ToHandler(h http.Handler) Handler

ToHandler adapts a github.com/malivvan/http Handler into a server Handler, so fork handlers (e.g. a fork http.ServeMux) can be mounted inside a server router or wrapped by server middlewares. A server ResponseWriter already satisfies the fork's ResponseWriter interface, so no writer conversion is needed.

type HandlerFunc

type HandlerFunc func(ResponseWriter, *Request)

HandlerFunc adapts a plain function to the Handler interface.

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(w ResponseWriter, r *Request)

ServeHTTP calls f(w, r).

type Middlewares

type Middlewares []func(Handler) Handler

Middlewares type is a slice of standard middleware handlers with methods to compose middleware chains and Handlers.

func Chain

func Chain(middlewares ...func(Handler) Handler) Middlewares

Chain returns a Middlewares type from a slice of middleware handlers.

func (Middlewares) Handler

func (mws Middlewares) Handler(h Handler) Handler

Handler builds and returns a Handler from the chain of middlewares, with `h Handler` as the final handler.

func (Middlewares) HandlerFunc

func (mws Middlewares) HandlerFunc(h HandlerFunc) Handler

HandlerFunc builds and returns a Handler from the chain of middlewares, with `h HandlerFunc` as the final handler.

type Mux

type Mux struct {
	// contains filtered or unexported fields
}

Mux is a simple HTTP route multiplexer that parses a request path, records any URL params, and executes an end handler. It implements the Handler interface and is friendly with the standard library.

Mux is designed to be fast, minimal and offer a powerful API for building modular and composable HTTP services with a large set of handlers. It's particularly useful for writing large REST API services that break a handler into many smaller parts composed of middlewares and end handlers.

func NewMux

func NewMux() *Mux

NewMux returns a newly initialized Mux object that implements the Router interface.

func NewRouter

func NewRouter() *Mux

NewRouter returns a new Mux object that implements the Router interface.

func (*Mux) Connect

func (mx *Mux) Connect(pattern string, handlerFn HandlerFunc)

Connect adds the route `pattern` that matches a CONNECT http method to execute the `handlerFn` HandlerFunc.

func (*Mux) Delete

func (mx *Mux) Delete(pattern string, handlerFn HandlerFunc)

Delete adds the route `pattern` that matches a DELETE http method to execute the `handlerFn` HandlerFunc.

func (*Mux) Find

func (mx *Mux) Find(rctx *Context, method, path string) string

Find searches the routing tree for the pattern that matches the method/path.

Note: the *Context state is updated during execution, so manage the state carefully or make a NewRouteContext().

func (*Mux) Get

func (mx *Mux) Get(pattern string, handlerFn HandlerFunc)

Get adds the route `pattern` that matches a GET http method to execute the `handlerFn` HandlerFunc.

func (*Mux) Group

func (mx *Mux) Group(fn func(r Router)) Router

Group creates a new inline-Mux with a copy of middleware stack. It's useful for a group of handlers along the same routing path that use an additional set of middlewares. See _examples/.

func (*Mux) Handle

func (mx *Mux) Handle(pattern string, handler Handler)

Handle adds the route `pattern` that matches any http method to execute the `handler` Handler.

func (*Mux) HandleFunc

func (mx *Mux) HandleFunc(pattern string, handlerFn HandlerFunc)

HandleFunc adds the route `pattern` that matches any http method to execute the `handlerFn` HandlerFunc.

func (*Mux) Head

func (mx *Mux) Head(pattern string, handlerFn HandlerFunc)

Head adds the route `pattern` that matches a HEAD http method to execute the `handlerFn` HandlerFunc.

func (*Mux) Match

func (mx *Mux) Match(rctx *Context, method, path string) bool

Match searches the routing tree for a handler that matches the method/path. It's similar to routing a http request, but without executing the handler thereafter.

Note: the *Context state is updated during execution, so manage the state carefully or make a NewRouteContext().

func (*Mux) Method

func (mx *Mux) Method(method, pattern string, handler Handler)

Method adds the route `pattern` that matches `method` http method to execute the `handler` Handler.

func (*Mux) MethodFunc

func (mx *Mux) MethodFunc(method, pattern string, handlerFn HandlerFunc)

MethodFunc adds the route `pattern` that matches `method` http method to execute the `handlerFn` HandlerFunc.

func (*Mux) MethodNotAllowed

func (mx *Mux) MethodNotAllowed(handlerFn HandlerFunc)

MethodNotAllowed sets a custom HandlerFunc for routing paths where the method is unresolved. The default handler returns a 405 with an empty body.

func (*Mux) MethodNotAllowedHandler

func (mx *Mux) MethodNotAllowedHandler(methodsAllowed ...methodTyp) HandlerFunc

MethodNotAllowedHandler returns the default Mux 405 responder whenever a method cannot be resolved for a route.

func (*Mux) Middlewares

func (mx *Mux) Middlewares() Middlewares

Middlewares returns a slice of middleware handler functions.

func (*Mux) Mount

func (mx *Mux) Mount(pattern string, handler Handler)

Mount attaches another Handler or chi Router as a subrouter along a routing path. It's very useful to split up a large API as many independent routers and compose them as a single service using Mount. See _examples/.

Note that Mount() simply sets a wildcard along the `pattern` that will continue routing at the `handler`, which in most cases is another server.Router. As a result, if you define two Mount() routes on the exact same pattern the mount will panic.

func (*Mux) NotFound

func (mx *Mux) NotFound(handlerFn HandlerFunc)

NotFound sets a custom HandlerFunc for routing paths that could not be found. The default 404 handler is `notFoundHandler`.

func (*Mux) NotFoundHandler

func (mx *Mux) NotFoundHandler() HandlerFunc

NotFoundHandler returns the default Mux 404 responder whenever a route cannot be found.

func (*Mux) Options

func (mx *Mux) Options(pattern string, handlerFn HandlerFunc)

Options adds the route `pattern` that matches an OPTIONS http method to execute the `handlerFn` HandlerFunc.

func (*Mux) Patch

func (mx *Mux) Patch(pattern string, handlerFn HandlerFunc)

Patch adds the route `pattern` that matches a PATCH http method to execute the `handlerFn` HandlerFunc.

func (*Mux) Post

func (mx *Mux) Post(pattern string, handlerFn HandlerFunc)

Post adds the route `pattern` that matches a POST http method to execute the `handlerFn` HandlerFunc.

func (*Mux) Put

func (mx *Mux) Put(pattern string, handlerFn HandlerFunc)

Put adds the route `pattern` that matches a PUT http method to execute the `handlerFn` HandlerFunc.

func (*Mux) Query

func (mx *Mux) Query(pattern string, handlerFn HandlerFunc)

Query adds the route `pattern` that matches a QUERY http method to execute the `handlerFn` HandlerFunc.

func (*Mux) Route

func (mx *Mux) Route(pattern string, fn func(r Router)) Router

Route creates a new Mux and mounts it along the `pattern` as a subrouter. Effectively, this is a short-hand call to Mount. See _examples/.

func (*Mux) Routes

func (mx *Mux) Routes() []Route

Routes returns a slice of routing information from the tree, useful for traversing available routes of a router.

func (*Mux) ServeHTTP

func (mx *Mux) ServeHTTP(w ResponseWriter, r *Request)

ServeHTTP is the single method of the Handler interface that makes Mux interoperable with the standard library. It uses a sync.Pool to get and reuse routing contexts for each request.

func (*Mux) Trace

func (mx *Mux) Trace(pattern string, handlerFn HandlerFunc)

Trace adds the route `pattern` that matches a TRACE http method to execute the `handlerFn` HandlerFunc.

func (*Mux) Use

func (mx *Mux) Use(middlewares ...func(Handler) Handler)

Use appends a middleware handler to the Mux middleware stack.

The middleware stack for any Mux will execute before searching for a matching route to a specific handler, which provides opportunity to respond early, change the course of the request execution, or set request-scoped values for the next Handler.

func (*Mux) With

func (mx *Mux) With(middlewares ...func(Handler) Handler) Router

With adds inline middlewares for an endpoint handler.

type Request

type Request struct {
	*http.Request

	// Fingerprint holds the full fingerprint data for this request: TLS
	// details (JA3, JA4, PeetPrint, ...) plus the protocol-specific HTTP/1,
	// HTTP/2 or HTTP/3 details.
	Fingerprint *fingerprint.Request

	// Pattern is the routing pattern that matched the request path, set by
	// the router while routing the request (e.g. "/users/{userID}/posts").
	Pattern string
	// contains filtered or unexported fields
}

Request is the request handed to a Handler. It embeds the standard *http.Request (URL, Header, Method, Host, RemoteAddr, Body, ...) and carries the fingerprint details collected for this connection.

func (*Request) PathValue

func (r *Request) PathValue(key string) string

PathValue returns the value for the named path segment, or "" if the segment has no value for this request.

func (*Request) SetPathValue

func (r *Request) SetPathValue(key, value string)

SetPathValue sets the value for the named path segment. It is used by the router to populate the values captured while matching the request path.

func (*Request) WithContext

func (r *Request) WithContext(ctx context.Context) *Request

WithContext returns a shallow copy of r with its context changed to ctx. Unlike the embedded *http.Request.WithContext, the result keeps the server Request fields (Fingerprint, Pattern and path values), so it can be assigned back to r in middlewares.

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Flusher

	// UpgradeWebSocket performs the WebSocket handshake. It returns
	// ErrNotWebSocket on connections that cannot be upgraded (HTTP/2
	// without RFC 8441 support, HTTP/3).
	UpgradeWebSocket(opts *websocket.AcceptOptions) (*websocket.Conn, error)

	// UpgradeWebTransport upgrades the request to a WebTransport session.
	// It returns ErrNotWebTransport on non-HTTP/3 connections.
	UpgradeWebTransport() (*webtransport.Session, error)
}

ResponseWriter is the writer handed to a Handler. Besides the standard http.ResponseWriter methods it allows upgrading the connection:

  • UpgradeWebSocket performs the WebSocket handshake on HTTP/1 connections and returns the established *websocket.Conn.
  • UpgradeWebTransport upgrades an HTTP/3 request to a WebTransport session and returns it.

func ToResponseWriter

func ToResponseWriter(w http.ResponseWriter) ResponseWriter

ToResponseWriter adapts a github.com/malivvan/http ResponseWriter into a server ResponseWriter. It forwards the standard response methods and the optional Flush / Push / ReadFrom capabilities of the wrapped writer, and reports ErrNotWebSocket / ErrNotWebTransport for connection upgrades.

type Route

type Route struct {
	SubRoutes Routes
	Handlers  map[string]Handler
	Pattern   string
}

Route describes the details of a routing handler. Handlers map key is an HTTP method

type RouteParams

type RouteParams struct {
	Keys, Values []string
}

RouteParams is a structure to track URL routing parameters efficiently.

func (*RouteParams) Add

func (s *RouteParams) Add(key, value string)

Add will append a URL parameter to the end of the route param

type Router

type Router interface {
	Handler
	Routes

	// Use appends one or more middlewares onto the Router stack.
	Use(middlewares ...func(Handler) Handler)

	// With adds inline middlewares for an endpoint handler.
	With(middlewares ...func(Handler) Handler) Router

	// Group adds a new inline-Router along the current routing
	// path, with a fresh middleware stack for the inline-Router.
	Group(fn func(r Router)) Router

	// Route mounts a sub-Router along a `pattern` string.
	Route(pattern string, fn func(r Router)) Router

	// Mount attaches another Handler along ./pattern/*
	Mount(pattern string, h Handler)

	// Handle and HandleFunc adds routes for `pattern` that matches
	// all HTTP methods.
	Handle(pattern string, h Handler)
	HandleFunc(pattern string, h HandlerFunc)

	// Method and MethodFunc adds routes for `pattern` that matches
	// the `method` HTTP method.
	Method(method, pattern string, h Handler)
	MethodFunc(method, pattern string, h HandlerFunc)

	// HTTP-method routing along `pattern`
	Connect(pattern string, h HandlerFunc)
	Delete(pattern string, h HandlerFunc)
	Get(pattern string, h HandlerFunc)
	Head(pattern string, h HandlerFunc)
	Options(pattern string, h HandlerFunc)
	Patch(pattern string, h HandlerFunc)
	Post(pattern string, h HandlerFunc)
	Put(pattern string, h HandlerFunc)
	Query(pattern string, h HandlerFunc)
	Trace(pattern string, h HandlerFunc)

	// NotFound defines a handler to respond whenever a route could
	// not be found.
	NotFound(h HandlerFunc)

	// MethodNotAllowed defines a handler to respond whenever a method is
	// not allowed.
	MethodNotAllowed(h HandlerFunc)
}

Router consisting of the core routing methods used by chi's Mux, using only the standard net/http.

type Routes

type Routes interface {
	// Routes returns the routing tree in an easily traversable structure.
	Routes() []Route

	// Middlewares returns the list of middlewares in use by the router.
	Middlewares() Middlewares

	// Match searches the routing tree for a handler that matches
	// the method/path - similar to routing a http request, but without
	// executing the handler thereafter.
	Match(rctx *Context, method, path string) bool

	// Find searches the routing tree for the pattern that matches
	// the method/path.
	Find(rctx *Context, method, path string) string
}

Routes interface adds two methods for router traversal, which is also used by the `docgen` subpackage to generation documentation for Routers.

type Server

type Server struct {
	// Addr is the address to bind (e.g. ":443"). It is only used when the
	// corresponding Listener/PacketConn field is nil; then the socket is
	// bound through the reuse package (SO_REUSEPORT/SO_REUSEADDR).
	Addr string

	// Handler receives every HTTP/1, HTTP/2, HTTP/3, WebSocket and
	// WebTransport request. A nil handler answers with 501.
	Handler Handler

	// TLSConfig configures TLS for the TCP (h1/h2/wss) and QUIC (h3)
	// listeners. If nil, certificates are provisioned from AutoCert when
	// set, otherwise ephemeral self-signed certificates are generated per
	// SNI host.
	TLSConfig *tls.Config

	// AutoCert, when set and TLSConfig is nil, provisions TLS certificates
	// automatically via golang.org/x/crypto/acme/autocert (e.g. Let's
	// Encrypt) for the SNI hosts the manager is configured with (HostPolicy
	// and Cache). The caller configures the Manager and is responsible for
	// serving the ACME http-01 challenges on port 80 via
	// autocert.Manager.HTTPHandler.
	AutoCert *autocert.Manager

	// Listener is the TCP listener for HTTP/1, HTTP/2 and WebSocket.
	// If nil, ListenAndServe binds Addr via the reuse package.
	Listener net.Listener

	// PacketConn is the UDP socket for HTTP/3 and WebTransport. If nil,
	// ListenAndServe binds Addr via the reuse package.
	PacketConn net.PacketConn

	// QUIC, when non-nil, starts the built-in QUIC (HTTP/3 + WebTransport)
	// server on the UDP socket with the given configuration. When nil, QUIC
	// is disabled. The QUIC matcher always has priority over user matchers
	// registered with MatchUDP.
	QUIC *quic.Config

	// Local marks local development mode. When set, TLS handshake errors of
	// the "unknown certificate" kind are swallowed instead of tearing down
	// the connection.
	Local bool

	// SniffDevice, when non-empty, enables passive TCP/IP fingerprinting:
	// packets destined for the TLS port are captured on the named network
	// interface (e.g. "eth0") and their IP/TCP fingerprints are attached to
	// matching requests as Request.Fingerprint.TCPIP.
	SniffDevice string
	// contains filtered or unexported fields
}

Server multiplexes one TCP and one UDP socket into HTTP/1.x, HTTP/2, WebSocket, HTTP/3 (QUIC) and WebTransport serving, plus any additional protocols the caller registers via MatchTCP/MatchUDP. It is modelled after http.Server: configuration lives in exported fields, and every request is dispatched to Handler with the request's fingerprint attached.

func NewServer

func NewServer(addr string) *Server

NewServer returns a Server that will bind addr (e.g. ":443" or "127.0.0.1:8443") when no Listener/PacketConn are provided.

func (*Server) Close

func (srv *Server) Close() error

Close immediately stops the server: it closes the multiplexers, the sockets and cancels the server context. In-flight requests are not waited for.

func (*Server) HandleTLSConnection

func (srv *Server) HandleTLSConnection(conn net.Conn) error

HandleTLSConnection reads the first bytes of a TLS connection, extracts the client fingerprint and dispatches the connection to the HTTP/1 or HTTP/2 handler.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

ListenAndServe shakes the server and blocks until the server shuts down or one of the serve loops fails.

func (*Server) MatchTCP

func (srv *Server) MatchTCP(matchers ...netmux.ConnMatcher) net.Listener

MatchTCP registers an additional protocol on the TCP socket. The returned net.Listener delivers connections whose leading bytes are accepted by one of the matchers; matchers are tried in registration order, before the built-in TLS catch-all. MatchTCP must be called before Shake/ListenAndServe.

func (*Server) MatchUDP

func (srv *Server) MatchUDP(matchers ...netmux.PacketConnMatcher) net.PacketConn

MatchUDP registers an additional protocol on the UDP socket. The returned net.PacketConn receives packets accepted by one of the matchers; user matchers are tried after the built-in QUIC matcher and before the netmux.AnyPacket() catch-all. MatchUDP must be called before Shake/ListenAndServe.

func (*Server) ServeTCP

func (srv *Server) ServeTCP(l net.Listener) error

ServeTCP starts only the TCP side (HTTP/1, HTTP/2, WebSocket and any TCP matchers) on the given listener and blocks until it fails or the server is shut down.

func (*Server) ServeUDP

func (srv *Server) ServeUDP(c net.PacketConn) error

ServeUDP starts only the UDP side (QUIC/WebTransport when QUIC is set, plus any UDP matchers) on the given packet conn and blocks until it fails or the server is shut down.

func (*Server) Shake

func (srv *Server) Shake() error

Shake binds the sockets (via the reuse package when Listener/PacketConn are nil), builds the netmux multiplexers, registers the built-in and user-provided matchers and starts serving. It returns once the sockets are bound and the serve loops are running. Shake is idempotent.

func (*Server) Shutdown

func (srv *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the server: it stops accepting new connections, waits for in-flight requests to finish and then returns. It returns ctx.Err() if the context expires first.

func (*Server) TCPFingerprints

func (srv *Server) TCPFingerprints() *sync.Map

TCPFingerprints returns the map of captured TCP/IP fingerprints, keyed by "sourceIP:sourcePort". It is populated when SniffDevice is set.

type WalkFunc

type WalkFunc func(method string, route string, handler Handler, middlewares ...func(Handler) Handler) error

WalkFunc is the type of the function called for each method and route visited by Walk.

Directories

Path Synopsis
Package autocert provides automatic access to certificates from Let's Encrypt and any other ACME-based CA.
Package autocert provides automatic access to certificates from Let's Encrypt and any other ACME-based CA.
acme
Package acme provides an implementation of the Automatic Certificate Management Environment (ACME) spec, most famously used by Let's Encrypt.
Package acme provides an implementation of the Automatic Certificate Management Environment (ACME) spec, most famously used by Let's Encrypt.
acmetest
Package acmetest provides types for testing acme and autocert packages.
Package acmetest provides types for testing acme and autocert packages.
examples
custom-handler command
custom-method command
fileserver command
This example demonstrates how to serve static files from your filesystem.
This example demonstrates how to serve static files from your filesystem.
fingerprint command
This example dumps the complete fingerprint collected for each incoming request: TLS details (JA3, JA4, PeetPrint, negotiated ciphers, SNI, ...), the HTTP/1 header order, HTTP/2 Akamai fingerprint or HTTP/3 settings fingerprint, and the TCP/IP details when packet capture is enabled.
This example dumps the complete fingerprint collected for each incoming request: TLS details (JA3, JA4, PeetPrint, negotiated ciphers, SNI, ...), the HTTP/1 header order, HTTP/2 Akamai fingerprint or HTTP/3 settings fingerprint, and the TCP/IP details when packet capture is enabled.
fingerprint-summary command
This example returns a compact JSON summary of the most commonly used fingerprint identifiers for each request: JA3, JA4, PeetPrint, the Akamai HTTP/2 fingerprint and the HTTP version.
This example returns a compact JSON summary of the most commonly used fingerprint identifiers for each request: JA3, JA4, PeetPrint, the Akamai HTTP/2 fingerprint and the HTTP version.
fingerprint-tcpip command
This example demonstrates passive TCP/IP fingerprinting: set the server's SniffDevice to a real network interface and the server captures packets destined for the TLS port on that interface, attaching the IP/TCP header details (window size, MSS, TTL, options order, ...) to each request.
This example demonstrates passive TCP/IP fingerprinting: set the server's SniffDevice to a real network interface and the server captures packets destined for the TLS port on that interface, attaching the IP/TCP header details (window size, MSS, TTL, options order, ...) to each request.
graceful command
hello-world command
limits command
This example demonstrates the use of Timeout, and Throttle middlewares.
This example demonstrates the use of Timeout, and Throttle middlewares.
logging command
This example demonstrates request logging with the built-in middleware.Logger.
This example demonstrates request logging with the built-in middleware.Logger.
pathvalue command
router-walk command
todos-resource command
This example demonstrates a project structure that defines a subrouter and its handlers on a struct, and mounting them as subrouters to a parent router.
This example demonstrates a project structure that defines a subrouter and its handlers on a struct, and mounting them as subrouters to a parent router.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL