|
@@ -23,6 +23,10 @@ type Option struct {
|
|
//
|
|
//
|
|
//}
|
|
//}
|
|
|
|
|
|
|
|
+func Register(r *gin.Engine, option *Option) {
|
|
|
|
+ r.GET(option.RelativePath+"/*any", Handler(option))
|
|
|
|
+}
|
|
|
|
+
|
|
func Handler(option *Option) gin.HandlerFunc {
|
|
func Handler(option *Option) gin.HandlerFunc {
|
|
|
|
|
|
if option.DocJsonPath == "" {
|
|
if option.DocJsonPath == "" {
|
|
@@ -33,17 +37,21 @@ func Handler(option *Option) gin.HandlerFunc {
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Printf("not found docJson in " + option.DocJsonPath)
|
|
log.Printf("not found docJson in " + option.DocJsonPath)
|
|
}
|
|
}
|
|
|
|
+ indexPath := option.RelativePath + "index.html"
|
|
|
|
+ servicesPath := option.RelativePath + "services.json"
|
|
|
|
+ docJsonPath := option.RelativePath + "doc.json"
|
|
|
|
|
|
return func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
switch c.Request.RequestURI {
|
|
switch c.Request.RequestURI {
|
|
- case "index.html":
|
|
|
|
|
|
+ case indexPath:
|
|
writeDocHtml(c)
|
|
writeDocHtml(c)
|
|
- case "services.json":
|
|
|
|
|
|
+ case servicesPath:
|
|
writeServicesJson(c)
|
|
writeServicesJson(c)
|
|
- case "doc.json":
|
|
|
|
|
|
+ case docJsonPath:
|
|
writeDocJson(c, docJson)
|
|
writeDocJson(c, docJson)
|
|
default:
|
|
default:
|
|
- filePath := strings.ReplaceAll(c.Request.RequestURI, option.RelativePath, "")
|
|
|
|
|
|
+ //filePath := strings.ReplaceAll(c.Request.RequestURI, option.RelativePath, "")
|
|
|
|
+ filePath := strings.TrimPrefix(c.Request.RequestURI, option.RelativePath)
|
|
c.FileFromFS(filePath, http.FS(front))
|
|
c.FileFromFS(filePath, http.FS(front))
|
|
}
|
|
}
|
|
}
|
|
}
|