swaggeruiemb

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 swaggeruiemb provides an embedded (air-gapped) Swagger UI for stdocs.

Unlike the sibling ui/swaggerui package, which loads Swagger UI from a CDN at page-load time, ui/swaggeruiemb vendors the Swagger UI JavaScript and CSS in your binary so the docs UI works without an internet connection.

The vendored bundle is pinned to swagger-ui-dist@5.32.6 and its sha384 SRI hash is set in the sibling ui/swaggerui package.

To use it:

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

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

The asset handler adds about 1.7 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 Swagger UI 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/", swaggeruiemb.AssetHandler()))

func WithUI

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

WithUI returns a stdocs.Option that replaces the default docs page with the embedded Swagger UI. Pass WithConfiguration to forward Swagger UI-native options; they override the CSP-safe defaults.

Types

type UIOption added in v0.7.0

type UIOption = uiopt.Option

UIOption configures the embedded Swagger UI installed by WithUI.

func WithConfiguration added in v0.7.0

func WithConfiguration(cfg map[string]any) UIOption

WithConfiguration passes Swagger UI configuration to the docs page. The map is merged over Swagger UI's SwaggerUIBundle({...}) options, so its keys are Swagger UI's parameters — for example "docExpansion", "filter", "defaultModelsExpandDepth", "tryItOutEnabled", or "displayRequestDuration". The "url" and "dom_id" are set by stdocs and always win. See the Swagger UI configuration reference: https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/

Jump to

Keyboard shortcuts

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