package docs
import (
"embed"
httptemplate "html/template"
"net/http"
"github.com/gorilla/mux"
)
const (
apiFile = "/static/openapi.yml"
indexFile = "template/index.tpl"
)
var Static embed.FS
var template embed.FS
func RegisterOpenAPIService(appName string, rtr *mux.Router) {
rtr.Handle(apiFile, http.FileServer(http.FS(Static)))
rtr.HandleFunc("/", handler(appName))
}
func handler(title string) http.HandlerFunc {
t, _ := httptemplate.ParseFS(template, indexFile)
return func(w http.ResponseWriter, req *http.Request) {
t.Execute(w, struct {
Title string
URL string
}{
title,
apiFile,
})
}
}