stoplightemb

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package stoplightemb provides an embedded (air-gapped) Stoplight Elements UI for stdocs.

Unlike the sibling ui/stoplight package, which loads Stoplight from a CDN at page-load time, ui/stoplightemb vendors the Stoplight web-component bundle in your binary so the docs UI works without an internet connection.

The vendored bundle is pinned to @stoplight/elements@9.0.22.

To use it:

import (
    "net/http"
    "github.com/FumingPower3925/stdocs"
    "github.com/FumingPower3925/stdocs/ui/stoplightemb"
)

mux := stdocs.New(stdocs.WithTitle("My API"), stoplightemb.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/", stoplightemb.AssetHandler()))

The asset handler adds about 2.4 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 Stoplight web components 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/", stoplightemb.AssetHandler()))

func WithUI

func WithUI(opts ...UIOption) stdocs.Option

WithUI returns a stdocs.Option that replaces the default docs page with the embedded Stoplight UI. Pass WithConfiguration to forward Stoplight-native options as element attributes.

Types

type UIOption added in v0.7.0

type UIOption = uiopt.Option

UIOption configures the embedded Stoplight Elements UI installed by WithUI.

func WithConfiguration added in v0.7.0

func WithConfiguration(cfg map[string]any) UIOption

WithConfiguration passes Stoplight Elements configuration to the docs page. Stoplight Elements has no JSON configuration object — it is configured through attributes on its <elements-api> element — so the map's keys are rendered as element attributes and its values must be strings, booleans, or numbers. Keys are Stoplight attribute names, for example "hideTryItPanel", "hideSchemas", "tryItCredentialsPolicy", or "logo". apiDescriptionUrl, router, and layout are set by stdocs and cannot be overridden. See the Stoplight Elements configuration reference: https://github.com/stoplightio/elements/blob/main/docs/getting-started/elements/elements-options.md

Jump to

Keyboard shortcuts

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