Bug Description
The fiber migrate --to v3.0.0 command produces invalid Go code when migrating the filesystem middleware to the new static middleware.
Issues Found
1. Invalid os.DirFS() usage with http.FS()
The migration tool generates:
app.Use("/static", static.New("", static.Config{
FS: os.DirFS(http.FS(embedFS)),
MaxAge: 24 * 60 * 60,
}))
This is invalid because http.FS() returns http.FileSystem, not a string path that os.DirFS() expects.
Correct code should be:
app.Use("/static", static.New("", static.Config{
FS: embedFS, // embed.FS implements fs.FS directly
MaxAge: 24 * 60 * 60,
}))
2. Import naming conflict
When a project has its own package named static (e.g., internal/web/static for embedded assets), the migration tool imports github.com/gofiber/fiber/v3/middleware/static without aliasing, causing a naming conflict:
import (
"github.com/gofiber/fiber/v3/middleware/static"
"myproject/internal/web/static" // Conflict!
)
Steps to Reproduce
-
Create a Fiber v2 project with:
- An embedded filesystem using
embed.FS
- A package named
static (e.g., internal/web/static)
- Usage of
filesystem.New() middleware
-
Run fiber migrate --to v3.0.0
-
Observe the generated code fails to compile
Expected Behavior
The migration tool should:
- Recognize that
embed.FS already implements fs.FS and use it directly
- Detect naming conflicts and add an alias (e.g.,
staticmw "github.com/gofiber/fiber/v3/middleware/static")
Environment
- Fiber CLI version: v0.11.3
- Go version: 1.25.7
- OS: Linux
Original Code (v2)
import (
"net/http"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"myproject/internal/web/static"
)
app.Use("/static", filesystem.New(filesystem.Config{
Root: http.FS(static.Static),
MaxAge: 24 * 60 * 60,
}))
Generated Code (broken)
import (
"os"
"net/http"
"github.com/gofiber/fiber/v3/middleware/static"
"myproject/internal/web/static" // CONFLICT
)
app.Use("/static", static.New("", static.Config{
FS: os.DirFS(http.FS(static.Static)), // INVALID
MaxAge: 24 * 60 * 60,
}))
Correct Code (manual fix)
import (
"github.com/gofiber/fiber/v3/middleware/static"
webstatic "myproject/internal/web/static" // Aliased
)
app.Use("/static", static.New("", static.Config{
FS: webstatic.Static, // Direct use of embed.FS
MaxAge: 24 * 60 * 60,
}))
Bug Description
The
fiber migrate --to v3.0.0command produces invalid Go code when migrating thefilesystemmiddleware to the newstaticmiddleware.Issues Found
1. Invalid
os.DirFS()usage withhttp.FS()The migration tool generates:
This is invalid because
http.FS()returnshttp.FileSystem, not a string path thatos.DirFS()expects.Correct code should be:
2. Import naming conflict
When a project has its own package named
static(e.g.,internal/web/staticfor embedded assets), the migration tool importsgithub.com/gofiber/fiber/v3/middleware/staticwithout aliasing, causing a naming conflict:Steps to Reproduce
Create a Fiber v2 project with:
embed.FSstatic(e.g.,internal/web/static)filesystem.New()middlewareRun
fiber migrate --to v3.0.0Observe the generated code fails to compile
Expected Behavior
The migration tool should:
embed.FSalready implementsfs.FSand use it directlystaticmw "github.com/gofiber/fiber/v3/middleware/static")Environment
Original Code (v2)
Generated Code (broken)
Correct Code (manual fix)