examples/

directory
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

README

Examples

Examples for the github.com/malivvan/server package. Each example is a small, runnable main package; run it from the module root:

go run ./examples/<name>

The server always serves TLS with an auto-generated self-signed certificate, so talk to it with curl -k (or a client that skips certificate verification), e.g.:

curl -k https://localhost:3333/

The examples add no new dependencies: they only import the server module itself (github.com/malivvan/server, github.com/malivvan/server/middleware, github.com/malivvan/server/fingerprint), the HTTP fork (github.com/malivvan/http) and the standard library.

Routing

  • hello-world — the classic "hello world": a router with the RequestID, Logger and Recoverer middleware and a single GET / route.
  • custom-handler — a custom Handler type whose ServeHTTP receives an error from the wrapped handler and answers with 503 when one is returned.
  • custom-method — registers the custom HTTP methods LINK, UNLINK and WOOHOO with server.RegisterMethod and routes them alongside the standard methods.
  • pathvalue — reads a URL path parameter (/users/{userID}) with server.Request.PathValue.
  • router-walk — prints the whole routing tree (method + pattern) by traversing the router with server.Walk.
  • todos-resource — a small REST-ish service built from struct-based subrouters (usersResource, todosResource) mounted onto a parent router.

Middleware

  • limitsmiddleware.Timeout cancels slow handlers after 2.5 seconds (or 30 seconds on the /throttled group) and middleware.Throttle(1) limits that path to one in-flight request at a time.
  • logging — request logging with middleware.RequestID + middleware.Logger: each request is logged with status, size and latency.

Lifecycle & files

  • graceful — starts the server in the background and shuts it down gracefully (server.Server.Shutdown) on SIGINT/SIGTERM, letting in-flight requests (e.g. the 5-second /slow handler) finish.
  • fileserver — serves static files from ./data/ under /files, with a 301 redirect from /files to /files/.

Fingerprinting

  • fingerprint — returns the complete fingerprint of each request as indented JSON: TLS details (JA3, JA4, PeetPrint, SNI, ciphers, ...), the HTTP/1 header order, the HTTP/2 Akamai fingerprint or HTTP/3 settings fingerprint.

  • fingerprint-summary — returns a compact JSON summary of the key identifiers: JA3, JA4, PeetPrint, the Akamai HTTP/2 fingerprint and the HTTP version.

  • fingerprint-tcpip — passive TCP/IP fingerprinting via server.Server.SniffDevice: IP/TCP header details (TTL, window size, MSS, options order, ...) captured with pcap and attached to each request. Requires root/libpcap and a real interface name:

    sudo go run ./examples/fingerprint-tcpip -device eth0
    curl -k https://localhost:8443/
    

Directories

Path Synopsis
This example demonstrates how to serve static files from your filesystem.
This example demonstrates how to serve static files from your filesystem.
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.
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.
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.
This example demonstrates the use of Timeout, and Throttle middlewares.
This example demonstrates the use of Timeout, and Throttle middlewares.
This example demonstrates request logging with the built-in middleware.Logger.
This example demonstrates request logging with the built-in middleware.Logger.
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