Files
nmon/internal/api/docs.go
jleung f85c3ef781
Some checks failed
ci / lint (push) Has been cancelled
ci / test (ubuntu-24.04-arm) (push) Has been cancelled
ci / test (ubuntu-latest) (push) Has been cancelled
ci / postgres (push) Has been cancelled
ci / openapi (push) Has been cancelled
M3: Go API per UI contract, embedded UI, openapi compat check, nmon-devtools, live gate + screenshots; M4 WP1 reachability and dependency suppression
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
2026-10-22 20:34:14 +00:00

32 lines
958 B
Go

package api
import (
"embed"
"io/fs"
"net/http"
)
// docsFS holds the Swagger UI page and its vendored swagger-ui-dist 5.17.14
// assets, so /docs works on a network with no internet access (huma's own
// renderers load their JavaScript from a CDN).
//
//go:embed docsui
var docsFS embed.FS
// registerDocs serves Swagger UI at /docs and its assets under /docs/assets/.
func registerDocs(mux *http.ServeMux) {
sub, err := fs.Sub(docsFS, "docsui")
if err != nil {
panic("api: embedded docs missing: " + err.Error()) // the embed directive guarantees the directory
}
page, err := fs.ReadFile(sub, "index.html")
if err != nil {
panic("api: embedded docs page missing: " + err.Error())
}
mux.HandleFunc("GET /docs", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = w.Write(page)
})
mux.Handle("GET /docs/assets/", http.StripPrefix("/docs/assets/", http.FileServerFS(sub)))
}