Documentation
¶
Overview ¶
Package redocemb provides an embedded (air-gapped) Redoc UI for stdocs.
Unlike the sibling ui/redoc package, which loads Redoc from a CDN at page-load time, ui/redocemb vendors the Redoc JavaScript bundle in your binary so the docs UI works without an internet connection.
The vendored bundle is pinned to redoc@2.5.3 and its sha384 SRI hash is set in the sibling ui/redoc package.
To use it:
import (
"net/http"
"github.com/FumingPower3925/stdocs"
"github.com/FumingPower3925/stdocs/ui/redocemb"
)
mux := stdocs.New(stdocs.WithTitle("My API"), redocemb.WithUI())
mux.HandleFunc("GET /x", h)
mux.Mount() // registers the docs AND the embedded asset route
Mount registers the asset route automatically (and tolerates a pre-existing manual registration). Only a manually mounted docs handler needs its own asset registration:
mux.ServeMux.Handle("GET /docs/", mux.Docs())
mux.ServeMux.Handle("GET /docs/_assets/", http.StripPrefix(
"/docs/_assets/", redocemb.AssetHandler()))
The asset handler adds about 1.1 MB to your binary and is only included if you import this sub-package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssetHandler ¶
AssetHandler returns an http.Handler that serves the embedded Redoc JavaScript bundle at the root. File responses carry an immutable Cache-Control header; directory requests return 404. Mount it on your mux with a path strip, e.g.:
mux.Handle("GET /docs/_assets/", http.StripPrefix("/docs/_assets/", redocemb.AssetHandler()))
Types ¶
This section is empty.