mirror of
https://github.com/Warky-Devs/vecna.git
synced 2026-05-05 01:26:58 +00:00
37 lines
909 B
Go
37 lines
909 B
Go
package spec
|
|
|
|
import (
|
|
_ "embed"
|
|
"net/http"
|
|
|
|
"github.com/uptrace/bunrouter"
|
|
)
|
|
|
|
//go:embed openapi.yaml
|
|
var openapiYAML []byte
|
|
|
|
// SpecHandler serves the raw OpenAPI YAML spec.
|
|
func SpecHandler() bunrouter.HandlerFunc {
|
|
return func(w http.ResponseWriter, req bunrouter.Request) error {
|
|
w.Header().Set("Content-Type", "application/yaml")
|
|
_, err := w.Write(openapiYAML)
|
|
return err
|
|
}
|
|
}
|
|
|
|
// DocsHandler serves the Scalar API reference UI.
|
|
func DocsHandler() bunrouter.HandlerFunc {
|
|
return func(w http.ResponseWriter, req bunrouter.Request) error {
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
_, err := w.Write([]byte(`<!doctype html>
|
|
<html>
|
|
<head><title>vecna API</title><meta charset="utf-8"/></head>
|
|
<body>
|
|
<script id="api-reference" data-url="/openapi.yaml"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
|
</body>
|
|
</html>`))
|
|
return err
|
|
}
|
|
}
|