package http import ( _ "embed" "net/http" ) //go:embed openapi_spec.json var openapiSpec []byte // DocsHandler serves the OpenAPI spec and Swagger UI. type DocsHandler struct { token string } // NewDocsHandler creates a handler for API documentation endpoints. func NewDocsHandler(token string) *DocsHandler { return &DocsHandler{token: token} } // RegisterRoutes registers documentation routes on the given mux. func (h *DocsHandler) RegisterRoutes(mux *http.ServeMux) { mux.HandleFunc("GET /v1/openapi.json", h.handleSpec) mux.HandleFunc("GET /docs", h.handleSwaggerUI) mux.HandleFunc("GET /docs/", h.handleSwaggerUI) } func (h *DocsHandler) handleSpec(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "application/json") w.Header().Set("Access-Control-Allow-Origin", "*") w.Write(openapiSpec) } func (h *DocsHandler) handleSwaggerUI(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Write([]byte(swaggerHTML)) } const swaggerHTML = `