-
-
Notifications
You must be signed in to change notification settings - Fork 493
migrate to v3 #3841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") |
csrf-with-session/main.go
Outdated
| if err != nil { | ||
| return c.SendStatus(fiber.StatusInternalServerError) | ||
| } | ||
| defer session.Release() // Important: Manual cleanup required |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
csrf-with-session/main.go
Outdated
| if err != nil { | ||
| return c.SendStatus(fiber.StatusInternalServerError) | ||
| } | ||
| defer session.Release() // Important: Manual cleanup required |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Session objects in Fiber v3 do not have a Release() method. These defer statements will cause compilation errors and should be removed.
csrf-with-session/main.go
Outdated
| if err != nil { | ||
| return c.SendStatus(fiber.StatusInternalServerError) | ||
| } | ||
| defer session.Release() // Important: Manual cleanup required |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Session objects in Fiber v3 do not have a Release() method. These defer statements will cause compilation errors and should be removed.
csrf-with-session/main.go
Outdated
| if err != nil { | ||
| return c.SendStatus(fiber.StatusInternalServerError) | ||
| } | ||
| defer session.Release() // Important: Manual cleanup required |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Session objects in Fiber v3 do not have a Release() method. These defer statements will cause compilation errors and should be removed.
ent-mysql/ent/client.go
Outdated
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer obj.Release() // Important: Manual cleanup required |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Implements migration to add defer sess.Release() calls for v3 session Store Pattern usage. In v3, sessions obtained via store.Get() and store.GetByID() must be manually released back to the pool. Key Features: - Parses imports to find v3 session package (skips v2) - Tracks session.NewStore() variables specifically - Scope-aware: verifies store variable is from session.NewStore() in current function scope to prevent false positives - Handles closures accessing parent scope variables - Adds defer Release() after error checks or immediately if no check - Prevents duplicates by checking for existing Release() calls - Safe with nil (Release() has nil guard) Edge Cases Handled: ✅ No error checking (sess, _ := store.Get(c)) ✅ Already has defer (no duplicates) ✅ Multiline error blocks ✅ Middleware pattern (correctly excluded - middleware manages lifecycle) ✅ False positives (cache.Get, Ent ORM, CSRF - correctly excluded) ✅ Various store variable names (store, sessionStore, myStore) ✅ V2 imports (correctly skipped - migration runs after v2→v3 upgrade) ✅ Cross-function variable name collision (store in session vs cache) ✅ Closures/anonymous functions accessing parent scope ✅ Real-world examples from gofiber/recipes verified Test Coverage: - 13 comprehensive tests covering all edge cases - Includes real-world patterns from csrf-with-session and ent-mysql - 0 linting issues Fixes gofiber/recipes#3841
…est handling with fiber client
…est handling with fiber client
|


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