upgrade: 优化文档主题处理
This commit is contained in:
@ -8,7 +8,6 @@
|
|||||||
package api_doc
|
package api_doc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -16,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"git.zhangdeman.cn/gateway/api-doc/define"
|
"git.zhangdeman.cn/gateway/api-doc/define"
|
||||||
"git.zhangdeman.cn/gateway/api-doc/enums"
|
"git.zhangdeman.cn/gateway/api-doc/enums"
|
||||||
|
"git.zhangdeman.cn/gateway/api-doc/theme"
|
||||||
"git.zhangdeman.cn/zhangdeman/consts"
|
"git.zhangdeman.cn/zhangdeman/consts"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
knife4goFiles "github.com/go-webtools/knife4go"
|
knife4goFiles "github.com/go-webtools/knife4go"
|
||||||
@ -24,12 +24,6 @@ import (
|
|||||||
ginSwagger "github.com/swaggo/gin-swagger"
|
ginSwagger "github.com/swaggo/gin-swagger"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed ydoc-lucky-ui/*
|
|
||||||
var ydocUIFiles embed.FS
|
|
||||||
|
|
||||||
//go:embed redoc-free/index.html
|
|
||||||
var redocFreeIndexContent string
|
|
||||||
|
|
||||||
// NewSwaggerUI ...
|
// NewSwaggerUI ...
|
||||||
func NewSwaggerUI(info *define.Info, servers []*define.ServerItem, uiTheme enums.SwaggerUITheme) *SwaggerUI {
|
func NewSwaggerUI(info *define.Info, servers []*define.ServerItem, uiTheme enums.SwaggerUITheme) *SwaggerUI {
|
||||||
return &SwaggerUI{
|
return &SwaggerUI{
|
||||||
@ -112,7 +106,7 @@ func (su *SwaggerUI) HandleLuckyUI() func(ctx *gin.Context) {
|
|||||||
// su.router.StaticFS(su.baseUri+"/assets", http.FS(ydocUIFiles))
|
// su.router.StaticFS(su.baseUri+"/assets", http.FS(ydocUIFiles))
|
||||||
return func(ctx *gin.Context) {
|
return func(ctx *gin.Context) {
|
||||||
fileRealPath := strings.TrimPrefix(ctx.Request.RequestURI, su.baseUri)
|
fileRealPath := strings.TrimPrefix(ctx.Request.RequestURI, su.baseUri)
|
||||||
byteData, _ := ydocUIFiles.ReadFile(filepath.Join(enums.SwaggerUIThemeYDocLucky.String(), fileRealPath))
|
byteData, _ := theme.YdocUIFiles.ReadFile(filepath.Join(enums.SwaggerUIThemeYDocLucky.String(), fileRealPath))
|
||||||
if strings.HasSuffix(ctx.Request.RequestURI, "html") {
|
if strings.HasSuffix(ctx.Request.RequestURI, "html") {
|
||||||
byteData = []byte(strings.ReplaceAll(string(byteData), "{{BASE_URI}}", su.baseUri))
|
byteData = []byte(strings.ReplaceAll(string(byteData), "{{BASE_URI}}", su.baseUri))
|
||||||
}
|
}
|
||||||
@ -156,10 +150,10 @@ func (su *SwaggerUI) HandleRedocFreeUI() func(ctx *gin.Context) {
|
|||||||
"{{REDOC_STANDALONE_JS}}": "https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js",
|
"{{REDOC_STANDALONE_JS}}": "https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js",
|
||||||
}
|
}
|
||||||
for k, v := range replaceTable {
|
for k, v := range replaceTable {
|
||||||
redocFreeIndexContent = strings.ReplaceAll(redocFreeIndexContent, k, v)
|
theme.RedocFreeIndexContent = strings.ReplaceAll(theme.RedocFreeIndexContent, k, v)
|
||||||
}
|
}
|
||||||
ctx.Header(consts.HeaderKeyContentType.String(), "text/html; charset=utf-8")
|
ctx.Header(consts.HeaderKeyContentType.String(), "text/html; charset=utf-8")
|
||||||
ctx.String(http.StatusOK, redocFreeIndexContent)
|
ctx.String(http.StatusOK, theme.RedocFreeIndexContent)
|
||||||
ctx.Abort()
|
ctx.Abort()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
theme/embed.go
Normal file
16
theme/embed.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Package theme ...
|
||||||
|
//
|
||||||
|
// Description : theme ...
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 2025-08-23 09:23
|
||||||
|
package theme
|
||||||
|
|
||||||
|
import "embed"
|
||||||
|
|
||||||
|
//go:embed ydoc-lucky-ui/*
|
||||||
|
var YdocUIFiles embed.FS
|
||||||
|
|
||||||
|
//go:embed redoc-free/index.html
|
||||||
|
var RedocFreeIndexContent string
|
Before Width: | Height: | Size: 156 B After Width: | Height: | Size: 156 B |
Before Width: | Height: | Size: 340 KiB After Width: | Height: | Size: 340 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
@ -10,6 +10,8 @@ package util
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.zhangdeman.cn/zhangdeman/consts"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetParameterDefaultLocation 获取参数的默认位置
|
// GetParameterDefaultLocation 获取参数的默认位置
|
||||||
|
Reference in New Issue
Block a user