Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.63 KB

README.md

File metadata and controls

58 lines (40 loc) · 1.63 KB

Scalar for Go

This package provides an easy way to render a beautiful API reference based on an OpenAPI/Swagger file with Scalar.

scalar

Installation

go get github.com/pakornv/scalar-go

Usage

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

Credits

License

The source code in this repository is licensed under MIT.