A Go package for embedding and serving Scalar UI with custom configurations. This package renders the full Scalar UI HTML template directly in Go and supports both URL-based and embedded OpenAPI specs.
- 🎨 Beautiful UI – Modern API documentation
- ⚡ Easy to Use – Render a full HTML page with one call
- 🎯 Fully Configurable – Themes, layout, auth, variables, CSS, servers, etc.
- 📦 Embedded Template – No external HTML required
- 🔗 Supports URL + Inline Specs
- 🔥 Optional Hot Reload – Auto-refresh when your spec changes
- 🛠️ Developer Tools – Built-in “Try It” request interface
go get github.com/nyxstack/scalaruipackage main
import (
"fmt"
"log"
"net/http"
"github.com/nyxstack/scalarui"
)
func main() {
config := scalarui.NewConfig().
WithTitle("My API Documentation").
WithURL("http://localhost:8080/openapi.yaml")
ui := scalarui.New(config)
http.HandleFunc("/docs", func(w http.ResponseWriter, r *http.Request) {
html, _ := ui.Render()
w.Header().Set("Content-Type", "text/html")
fmt.Fprint(w, html)
})
http.HandleFunc("/openapi.yaml", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "openapi.yaml")
})
log.Println("Docs at http://localhost:8080/docs")
log.Fatal(http.ListenAndServe(":8080", nil))
}config := scalarui.NewConfig().
WithTitle("My API").
WithDescription("API documentation").
WithURL("http://localhost:8080/openapi.yaml")config := scalarui.NewConfig().
WithTheme("purple").
WithDarkMode(true).
WithCustomCSS(`.scalar-app { --scalar-color-accent: #7c3aed }`).
WithVariable("primary-color", "#7c3aed")config.
WithSidebar(true).
WithDeveloperTools(true). // always | never | localhost
WithInteractive(true).
HideHTTPMethods().
HideModelsSection().
HideDownload()config.WithAuthentication(map[string]any{
"bearerAuth": map[string]any{
"type": "bearer",
"token": "your-token",
},
})config.
WithServer("https://api.prod.com", "Production").
WithServer("https://api.staging.com", "Staging")config.WithContent(`{"openapi":"3.0.0","info":{"title":"X"}}`)var startTime = time.Now()
func hotReload(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintf(w, "%d", startTime.Unix())
}http.HandleFunc("/hot-reload", hotReload)config.HotReloadURL = "/hot-reload"The UI will auto-refresh when the timestamp changes.
NewConfig()New(config)NewWithDefaults()Render()
r.GET("/docs", func(c *gin.Context) {
out, _ := ui.Render()
c.Header("Content-Type", "text/html")
c.String(200, out)
})e.GET("/docs", func(c echo.Context) error {
out, _ := ui.Render()
return c.HTML(200, out)
})MIT License
Contributions are welcome! Please feel free to submit a Pull Request.