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