diff --git a/go.mod b/go.mod index 21ed0e3..dacab06 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.15 require ( github.com/gofiber/fiber/v2 v2.32.0 github.com/stretchr/testify v1.7.0 - github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe + github.com/swaggo/files/v2 v2.0.0 github.com/swaggo/swag v1.8.1 github.com/valyala/fasthttp v1.36.0 ) diff --git a/go.sum b/go.sum index 266897c..c93d40f 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe h1:K8pHPVoTgxFJt1lXuIzzOX7zZhZFldJQK/CgKx9BFIc= -github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe/go.mod h1:lKJPbtWzJ9JhsTN1k1gZgleJWY/cqq0psdoMmaThG3w= +github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw= +github.com/swaggo/files/v2 v2.0.0/go.mod h1:24kk2Y9NYEJ5lHuCra6iVwkMjIekMCaFq/0JQj66kyM= github.com/swaggo/swag v1.8.1 h1:JuARzFX1Z1njbCGz+ZytBR15TFJwF2Q7fu8puJHhQYI= github.com/swaggo/swag v1.8.1/go.mod h1:ugemnJsPZm/kRwFUnzBlbHRd0JY9zE1M4F+uy2pAaPQ= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= diff --git a/swagger.go b/swagger.go index 2f3a6a3..a82038c 100644 --- a/swagger.go +++ b/swagger.go @@ -1,16 +1,14 @@ package fiberSwagger import ( + "github.com/gofiber/fiber/v2" + swaggerFiles "github.com/swaggo/files/v2" + "github.com/swaggo/swag" + "github.com/valyala/fasthttp/fasthttpadaptor" "html/template" "net/http" "path/filepath" "regexp" - "sync" - - "github.com/gofiber/fiber/v2" - swaggerFiles "github.com/swaggo/files" - "github.com/swaggo/swag" - "github.com/valyala/fasthttp/fasthttpadaptor" ) // Config stores fiberSwagger configuration variables. @@ -73,10 +71,6 @@ var WrapHandler = FiberWrapHandler() // FiberWrapHandler wraps `http.Handler` into `fiber.Handler`. func FiberWrapHandler(configFns ...func(c *Config)) fiber.Handler { - var once sync.Once - - handler := swaggerFiles.Handler - config := Config{ URL: "doc.json", DocExpansion: "list", @@ -98,14 +92,10 @@ func FiberWrapHandler(configFns ...func(c *Config)) fiber.Handler { matches := re.FindStringSubmatch(string(ctx.Request().URI().Path())) path := matches[2] - once.Do(func() { - handler.Prefix = matches[1] - }) - fileExt := filepath.Ext(path) switch path { case "": - return ctx.Redirect(filepath.Join(handler.Prefix, "index.html"), fiber.StatusMovedPermanently) + return ctx.Redirect(filepath.Join(matches[1], "index.html"), fiber.StatusMovedPermanently) case "index.html": ctx.Type(fileExt[0:], "utf-8") @@ -122,7 +112,7 @@ func FiberWrapHandler(configFns ...func(c *Config)) fiber.Handler { ctx.Type(fileExt[0:], "utf-8") return ctx.SendString(doc) default: - fasthttpadaptor.NewFastHTTPHandler(handler)(ctx.Context()) + fasthttpadaptor.NewFastHTTPHandler(http.FileServer(http.FS(swaggerFiles.FS)))(ctx.Context()) switch fileExt { case ".css":