Documentation
¶
Overview ¶
Package scalaremb provides an embedded (air-gapped) Scalar UI for stdocs.
Unlike the sibling ui/scalar package, which loads Scalar from a CDN at page-load time, ui/scalaremb vendors the Scalar JavaScript bundle in your binary so the docs UI works without an internet connection.
The vendored bundle is pinned to @scalar/api-reference@1.59.2 and ships in-repo, so importing this package is all you need; the //go:generate directive below is a maintainer-only convenience for re-vendoring the bundle on a version bump.
To use it:
import (
"net/http"
"github.com/FumingPower3925/stdocs"
"github.com/FumingPower3925/stdocs/ui/scalaremb"
)
mux := stdocs.New(stdocs.WithTitle("My API"), scalaremb.WithUI())
mux.HandleFunc("GET /x", h)
mux.Mount()
mux.Handle("GET /docs/_assets/", http.StripPrefix(
"/docs/_assets/", scalaremb.AssetHandler()))
The asset handler adds about 3.6 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 Scalar 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/", scalaremb.AssetHandler()))
Types ¶
This section is empty.