Skip to content

Commit

Permalink
optimize rest doc
Browse files Browse the repository at this point in the history
  • Loading branch information
wubin1989 committed May 20, 2024
1 parent 9c72280 commit 756bf0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions framework/rest/dochandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"fmt"
"github.com/rs/cors"
"github.com/unionj-cloud/go-doudou/v2/toolkit/stringutils"
"html/template"
"net/http"
"strings"
"text/template"
)

// window.docs = [
Expand Down Expand Up @@ -45,7 +45,9 @@ func docRoutes(doc string) []Route {
err error
buf bytes.Buffer
)
if tpl, err = template.New("onlinedoc.tmpl").Parse(onlinedocTmpl); err != nil {
if tpl, err = template.New("onlinedoc.tmpl").Parse(`window.doc = {{ .Doc }}
window.docUrl = "{{ .DocUrl }}"
window.docs = {{ .Docs }}`); err != nil {
panic(err)
}
docUrl := "openapi.json"
Expand All @@ -62,7 +64,8 @@ func docRoutes(doc string) []Route {
panic(err)
}
_writer.Header().Set("Content-Type", "text/html; charset=utf-8")
_writer.Write(buf.Bytes())
result := head + buf.String() + tail
_writer.Write([]byte(result))
},
},
{
Expand Down
4 changes: 3 additions & 1 deletion framework/rest/docindex.go

Large diffs are not rendered by default.

0 comments on commit 756bf0a

Please sign in to comment.