Julian Strobl 7810d08780
Add initial generated code
```
$ ignite version
Ignite CLI version:             v0.27.1
Cosmos SDK version:             v0.47.3

$ ignite scaffold chain planetmint-go --address-prefix plmt --no-module
```

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
2023-06-27 13:15:02 +02:00

41 lines
770 B
Go

package docs
import (
"embed"
httptemplate "html/template"
"net/http"
"github.com/gorilla/mux"
)
const (
apiFile = "/static/openapi.yml"
indexFile = "template/index.tpl"
)
//go:embed static
var Static embed.FS
//go:embed template
var template embed.FS
func RegisterOpenAPIService(appName string, rtr *mux.Router) {
rtr.Handle(apiFile, http.FileServer(http.FS(Static)))
rtr.HandleFunc("/", handler(appName))
}
// handler returns an http handler that servers OpenAPI console for an OpenAPI spec at specURL.
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,
})
}
}