Ver código fonte

修改 模块配置

钟志权 1 ano atrás
pai
commit
4c50040a55
1 arquivos alterados com 12 adições e 4 exclusões
  1. 12 4
      knife4gin/knife4gin.go

+ 12 - 4
knife4gin/knife4gin.go

@@ -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 {
 
 	if option.DocJsonPath == "" {
@@ -33,17 +37,21 @@ func Handler(option *Option) gin.HandlerFunc {
 	if err != nil {
 		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) {
 		switch c.Request.RequestURI {
-		case "index.html":
+		case indexPath:
 			writeDocHtml(c)
-		case "services.json":
+		case servicesPath:
 			writeServicesJson(c)
-		case "doc.json":
+		case docJsonPath:
 			writeDocJson(c, docJson)
 		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))
 		}
 	}