forked from lavanet/lava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs.go
43 lines (35 loc) · 836 Bytes
/
docs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package docs
import (
"embed"
httptemplate "html/template"
"net/http"
"github.com/gorilla/mux"
)
const (
apiFilePath = "/static/openapi.yml"
indexTemplatePath = "template/index.tpl"
)
//go:embed static
var staticFiles embed.FS
//go:embed template
var templateFiles embed.FS
func RegisterOpenAPIService(appName string, rtr *mux.Router) {
rtr.Handle(apiFilePath, http.FileServer(http.FS(staticFiles)))
rtr.HandleFunc("/", handler(appName))
}
// openapi handler returns a handler that serves the openapi documentation
func handler(title string) http.HandlerFunc {
t, err := httptemplate.ParseFS(templateFiles, indexTemplatePath)
if err != nil {
panic(err)
}
return func(w http.ResponseWriter, req *http.Request) {
t.Execute(w, struct {
Title string
URL string
}{
title,
apiFilePath,
})
}
}