scalaremb

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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() // 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/", 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

func AssetHandler() http.Handler

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

func WithUI

func WithUI() stdocs.Option

WithUI returns a stdocs.Option that replaces the default docs page with the embedded Scalar UI.

Types

This section is empty.

Jump to

Keyboard shortcuts

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