migrate to v3#3841
Conversation
git checkout master -- . ':!.github' ':!*.md' find . -name go.mod -execdir sh -c 'echo "=== $(pwd) ==="; fiber migrate --to v3.0.0-rc.3 -f' \;
|
Note The number of changes in this pull request is too large for Gemini Code Assist to generate a summary. |
build-errors.log |
|
swagggo, swaggerui, jwt contrib migration ERROR ERROR ERROR -> statuscode splitting -> gofiber/cli#229 |
|
ERROR |
|
ERROR |
build-errors.log |
build-errors.log |
|
only 4 problems left FAIL: ./docker-mariadb-clean-arch (appending to build-errors.log) -> JWT -> FIX gofiber/cli#245 EXPECTED: Dependent pkg: |
This commit adds two critical migrations to fix session-related issues in PR #3841: 1. Storage Version Migration (storage_versions.go): - Migrates storage package imports to their latest versions - Handles v2 → v3 upgrades for redis and postgres - Handles unversioned → v2 upgrades for 17 adapters - Leaves v1/unversioned packages unchanged - Comprehensive version mapping based on actual package versions 2. Session Release Migration (session_release.go): - Adds defer sess.Release() for legacy Store Pattern in Fiber v3 - Detects sess, err := store.Get(c) patterns - Intelligently inserts defer after error check blocks - Idempotent - won't add duplicate defer statements Both migrations include comprehensive test coverage: - 5 test scenarios for storage versions - 4 test scenarios for session release - All 270 tests passing - 0 linting issues Fixes: gofiber/recipes#3841
The session migration failed because the |
There was a problem hiding this comment.
Pull request overview
This PR migrates the codebase from Fiber v2 to v3 (release candidate 3). The migration involves updating package imports, modifying handler function signatures, and adapting to v3 API changes including binding methods, static file serving, CORS configuration, and session management.
Key Changes
- Updated all Fiber imports from
v2tov3and contrib packages tov3 - Changed handler signatures from
*fiber.Ctxtofiber.Ctx(value receiver) - Migrated
BodyParser()calls toBind().Body() - Updated static file serving and middleware configurations
Reviewed changes
Copilot reviewed 226 out of 349 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| Multiple go.mod files | Updated Fiber dependency from v2 to v3.0.0-rc.3 and updated related packages |
| Handler files (e.g., swagger/handlers/book.go) | Changed function signatures to use value receiver and updated BodyParser to Bind().Body() |
| Static file serving files | Migrated from app.Static() to static.New() middleware |
| CORS configuration files | Changed string values to string slices for AllowOrigins and AllowHeaders |
| Session files | Updated session.New() to session.NewStore() and configuration properties |
| Context method calls | Changed c.Context() to c.RequestCtx() and c.UserContext() to c.Context() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // TODO: migrate KeyLookup: strings.Join([]string{authSrc, authName}, ":") | ||
| Validator: validator, |
There was a problem hiding this comment.
This TODO comment should be addressed as part of the v3 migration. The KeyLookup configuration needs to be migrated to the new Extractor API pattern used in v3, similar to how it's done in other files in this PR (e.g., using extractors.FromHeader or similar).
| // TODO: migrate KeyLookup: strings.Join([]string{authSrc, authName}, ":") | |
| Validator: validator, | |
| KeyLookup: authSrc + ":" + authName, | |
| Validator: validator, |
| func GetBook(c *fiber.Ctx) error { | ||
| id, _ := c.ParamsInt("id") | ||
| func GetBook(c fiber.Ctx) error { | ||
| id, _ := fiber.Params[int](c, "id"), error(nil) |
There was a problem hiding this comment.
The error is being incorrectly assigned to error(nil) which creates a nil error value, discarding the actual error from fiber.Params. This should be: id, err := fiber.Params[int](c, \"id\") and the error should be properly handled.
| func DeleteBook(c *fiber.Ctx) error { | ||
| id, _ := c.ParamsInt("id") | ||
| func DeleteBook(c fiber.Ctx) error { | ||
| id, _ := fiber.Params[int](c, "id"), error(nil) |
There was a problem hiding this comment.
Same error handling issue as line 15 - the error from fiber.Params is being discarded and replaced with error(nil). Each occurrence should properly capture and handle the error.
| title := c.Query("title") | ||
| author := c.Query("author") | ||
| id, _ := c.ParamsInt("id") | ||
| id, _ := fiber.Params[int](c, "id"), error(nil) |
There was a problem hiding this comment.
Same error handling issue as line 15 - the error from fiber.Params is being discarded and replaced with error(nil). Each occurrence should properly capture and handle the error.
|
|
||
| // Fetch parameter. | ||
| targetedUserID, err := c.ParamsInt("userID") | ||
| targetedUserID, err := fiber.Params[int](c, "userID"), error(nil) |
There was a problem hiding this comment.
The error is being incorrectly assigned to error(nil). This should be targetedUserID, err := fiber.Params[int](c, \"userID\") to properly capture parameter parsing errors.
| targetedUserID, err := fiber.Params[int](c, "userID"), error(nil) | |
| targetedUserID, err := fiber.Params[int](c, "userID") |
| if err != nil { | ||
| return c.SendStatus(fiber.StatusInternalServerError) | ||
| } | ||
| defer session.Release() // Important: Manual cleanup required |
There was a problem hiding this comment.
Session objects in Fiber v3 do not have a Release() method. These defer statements will cause compilation errors and should be removed.
| defer session.Release() // Important: Manual cleanup required |
| if err != nil { | ||
| return c.SendStatus(fiber.StatusInternalServerError) | ||
| } | ||
| defer session.Release() // Important: Manual cleanup required |
There was a problem hiding this comment.
Session objects in Fiber v3 do not have a Release() method. These defer statements will cause compilation errors and should be removed.
| if err != nil { | ||
| return c.SendStatus(fiber.StatusInternalServerError) | ||
| } | ||
| defer session.Release() // Important: Manual cleanup required |
There was a problem hiding this comment.
Session objects in Fiber v3 do not have a Release() method. These defer statements will cause compilation errors and should be removed.
| if err != nil { | ||
| return c.SendStatus(fiber.StatusInternalServerError) | ||
| } | ||
| defer session.Release() // Important: Manual cleanup required |
There was a problem hiding this comment.
Session objects in Fiber v3 do not have a Release() method. These defer statements will cause compilation errors and should be removed.
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer obj.Release() // Important: Manual cleanup required |
There was a problem hiding this comment.
The Book entity returned by GetX() does not have a Release() method. This defer statement should be removed as it will cause a compilation error.
| defer obj.Release() // Important: Manual cleanup required |
build-errors.log==== ./aws-sam/app ====
# app
---- source: ./aws-sam/app/./main.go:26 ----
25
26 fiberLambda = fiberAdapter.New(app)
27 }
Error: ./main.go:26:33: cannot use app (variable of type *"github.com/gofiber/fiber/v3".App) as *"github.com/gofiber/fiber/v2".App value in argument to fiberAdapter.New
==== ./dummyjson ====
# main
---- source: ./dummyjson/./main.go:27 ----
26 }
27 defer resp.Release() // Important: Manual cleanup required
28
Error: ./main.go:27:14: resp.Release undefined (type *http.Response has no field or method Release)
==== ./ent-mysql ====
# ent-mysql/ent
---- source: ./ent-mysql/ent/client.go:281 ----
280 }
281 defer obj.Release() // Important: Manual cleanup required
282 return obj
Error: ent/client.go:281:12: obj.Release undefined (type *Book has no field or method Release)
==== ./entgo-sveltekit ====
# app/entity
---- source: ./entgo-sveltekit/entity/client.go:282 ----
281 }
282 defer obj.Release() // Important: Manual cleanup required
283 return obj
Error: entity/client.go:282:12: obj.Release undefined (type *Todo has no field or method Release)
==== ./monitoring-with-apitally ====
# main
---- source: ./monitoring-with-apitally/./main.go:50 ----
49 }
50 apitally.SetConsumer(c, consumer)
51 return true, nil
Error: ./main.go:50:25: cannot use c (variable of interface type "github.com/gofiber/fiber/v3".Ctx) as *"github.com/gofiber/fiber/v2".Ctx value in argument to apitally.SetConsumer
---- source: ./monitoring-with-apitally/./main.go:70 ----
69
70 app.Use(apitally.Middleware(app, cfg))
71
Error: ./main.go:70:30: cannot use app (variable of type *"github.com/gofiber/fiber/v3".App) as *"github.com/gofiber/fiber/v2".App value in argument to apitally.Middleware
---- source: ./monitoring-with-apitally/./main.go:95 ----
94 // Capture validation errors in Apitally
95 apitally.CaptureValidationError(c, err)
96 return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": err.Error()})
Error: ./main.go:95:36: cannot use c (variable of interface type "github.com/gofiber/fiber/v3".Ctx) as *"github.com/gofiber/fiber/v2".Ctx value in argument to apitally.CaptureValidationError
==== ./oauth2 ====
# oauth2/middleware
---- source: ./oauth2/middleware/auth.go:25 ----
24
25 a := fiber.AcquireAgent()
26 req := a.Request()
Error: middleware/auth.go:25:13: undefined: fiber.AcquireAgent
==== ./openapi ====
# openapi/routes
---- source: ./openapi/routes/routes.go:23 ----
22
23 api := humafiber.New(app, huma.DefaultConfig("Book API", "1.0.0"))
24 group := huma.NewGroup(api, "/v1")
Error: routes/routes.go:23:23: cannot use app (variable of type *"github.com/gofiber/fiber/v3".App) as *"github.com/gofiber/fiber/v2".App value in argument to humafiber.New
==== ./sveltekit-embed ====
# app
---- source: ./sveltekit-embed/./main.go:34 ----
33 app.All("/*", static.New("", static.Config{
34 FS: os.DirFS(template.Dist()),
35 // TODO: Migrate to NotFoundHandler (fiber.Handler) - NotFoundFile is deprecated
Error: ./main.go:34:16: cannot use template.Dist() (value of interface type http.FileSystem) as string value in argument to os.DirFS |
|
@sixcolors you new feature is selecting the wrong code , sometimes Line 27 in 1b2b81b recipes/ent-mysql/ent/client.go Line 281 in 1b2b81b
|
|
@efectn my client migrator is unfortantly not really working https://github.com/gofiber/recipes/blob/v3_migration/oauth2/middleware/auth.go#L25-L32 |
# Conflicts: # bootstrap/go.mod # bootstrap/go.sum # csrf-with-session/go.sum # csrf/go.sum # docker-mariadb-clean-arch/go.sum # firebase-functions/go.mod # geoip/go.sum # local-development-testcontainers/go.sum # minio/go.sum # monitoring-with-apitally/go.mod # monitoring-with-apitally/go.sum # svelte-netlify/go.sum # url-shortener-api/api/go.mod
…est handling with fiber client
…est handling with fiber client
|
# Conflicts: # aws-ses-sender/go.mod # aws-ses-sender/go.sum # ent-mysql/go.mod # ent-mysql/go.sum # entgo-sveltekit/go.mod # entgo-sveltekit/go.sum # local-development-testcontainers/go.mod # local-development-testcontainers/go.sum
|
# Conflicts: # firebase-auth/go.mod # firebase-auth/go.sum # firebase-functions/go.mod # firebase-functions/go.sum # gcloud-firebase/go.mod # gcloud-firebase/go.sum # swagger/go.mod
# Conflicts: # bootstrap/go.mod # bootstrap/go.sum # csrf-with-session/go.mod # csrf-with-session/go.sum # csrf/go.sum # geoip/go.mod # geoip/go.sum # i18n/go.mod # i18n/go.sum # oauth2/go.mod # oauth2/go.sum # rss-feed/go.mod # rss-feed/go.sum # sessions-sqlite3/go.mod # sessions-sqlite3/go.sum # svelte-netlify/go.mod # svelte-netlify/go.sum # template-asset-bundling/go.mod # template-asset-bundling/go.sum # template/go.mod # template/go.sum


Uh oh!
There was an error while loading. Please reload this page.