Added swagger themes

This commit is contained in:
2022-11-30 16:46:55 +01:00
parent b6e8d037a0
commit 0ff1188c3d
10 changed files with 11878 additions and 12 deletions

View File

@@ -9,12 +9,12 @@ import (
"strings"
)
//go:embed index.html
//go:embed swagger.json
//go:embed swagger.yaml
//go:embed swagger-ui-bundle.js
//go:embed swagger-ui.css
//go:embed swagger-ui-standalone-preset.js
//go:embed *.html
//go:embed *.json
//go:embed *.yaml
//go:embed *.js
//go:embed *.css
//go:embed themes/*
var assets embed.FS
func getAsset(fn string) ([]byte, string, bool) {
@@ -47,7 +47,8 @@ func getAsset(fn string) ([]byte, string, bool) {
func Handle(g *gin.Context) ginresp.HTTPResponse {
type uri struct {
Filename string `uri:"fn"`
Filename1 string `uri:"fn1"`
Filename2 *string `uri:"fn2"`
}
var u uri
@@ -55,14 +56,19 @@ func Handle(g *gin.Context) ginresp.HTTPResponse {
return ginresp.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
}
if u.Filename == "" {
filename := u.Filename1
if u.Filename2 != nil {
filename = filename + "/" + *u.Filename2
}
if filename == "" {
index, _, _ := getAsset("index.html")
return ginresp.Data(http.StatusOK, "text/html", index)
}
if data, mime, ok := getAsset(u.Filename); ok {
if data, mime, ok := getAsset(filename); ok {
return ginresp.Data(http.StatusOK, mime, data)
}
return ginresp.JSON(http.StatusNotFound, gin.H{"error": "AssetNotFound", "filename": u.Filename})
return ginresp.JSON(http.StatusNotFound, gin.H{"error": "AssetNotFound", "filename": filename, "filename1": u.Filename1, "filename2": u.Filename2})
}