This package provides an easy way to render a beautiful API reference based on an OpenAPI/Swagger file with Scalar.
go get github.com/pakornv/scalar-go
See Scalar official documentation for more configuration details.
package main
import (
"net/http"
"github.com/pakornv/scalar-go"
)
func main() {
apiRef, err := scalar.New("https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml")
if err != nil {
panic(err)
}
router := http.NewServeMux()
router.HandleFunc("GET /reference", func(w http.ResponseWriter, r *http.Request) {
htmlContent, err := apiRef.RenderHTML()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write([]byte(htmlContent))
})
http.ListenAndServe(":3000", router)
}
The source code in this repository is licensed under MIT.