swaggeruiemb

package
v0.5.0 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 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() stdocs.Option

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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