refactor(api): migrate backend from Fiber v2 to v3#928
Conversation
- Bump gofiber/fiber to v3.3.0 via fiber migrate CLI - Swap contrib deps: otelfiber -> contrib/v3/otel, swagger -> contrib/v3/swaggo - Update routing to v3 signature via new handler.register() helper - Adapt cors.Config to []string fields with splitCommaEnv() helper - *fiber.Ctx -> fiber.Ctx across handlers/middlewares Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Greptile SummaryMigrates the Go backend from
Confidence Score: 4/5The backend is safe to merge — all breaking changes from Fiber v2 to v3 are handled correctly across ~50 call sites with no handler or middleware left behind. The migration is mechanically thorough: the new register helper correctly uses Fiber v3's Add([]string, path, any, ...any) signature, the *fiber.Ctx → fiber.Ctx interface change is applied everywhere, body/query binding uses the new Bind API, and c.UserContext() → c.Context() in the OTel tracer is the right v3 equivalent. A leftover migration tool annotation in otel_tracer.go and an unverified integration path (API-key extraction via request body through the new Bind API) are the only open items, both minor. api/pkg/telemetry/otel_tracer.go (leftover migration comment) and api/pkg/middlewares/api_key_auth_middleware.go (body-based API key path with the new Bind API) are worth a quick check before merging. Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Client
participant Fiber v3 App
participant Middleware Chain
participant Handler
Note over Fiber v3 App: register() helper
Note over Fiber v3 App: router.Add([]string{method}, path, handlers[0], handlers[1:]...)
Client->>Fiber v3 App: HTTP Request
Fiber v3 App->>Middleware Chain: CORS → OtelFiber → Logger → Auth middleware(s)
Middleware Chain->>Middleware Chain: c.Bind().Body() / c.Bind().Query()
Middleware Chain->>Handler: fiber.Ctx (interface, not pointer)
Handler->>Handler: c.Bind().Body() or c.Bind().Query()
Handler-->>Client: JSON response
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Client
participant Fiber v3 App
participant Middleware Chain
participant Handler
Note over Fiber v3 App: register() helper
Note over Fiber v3 App: router.Add([]string{method}, path, handlers[0], handlers[1:]...)
Client->>Fiber v3 App: HTTP Request
Fiber v3 App->>Middleware Chain: CORS → OtelFiber → Logger → Auth middleware(s)
Middleware Chain->>Middleware Chain: c.Bind().Body() / c.Bind().Query()
Middleware Chain->>Handler: fiber.Ctx (interface, not pointer)
Handler->>Handler: c.Bind().Body() or c.Bind().Query()
Handler-->>Client: JSON response
Reviews (1): Last reviewed commit: "refactor(api): migrate backend from Fibe..." | Re-trigger Greptile |
| return strings.ReplaceAll(frame.Function, "github.com/NdoleStudio/http-sms-manager/", "") | ||
| } | ||
|
|
||
| // fiber:context-methods migrated |
There was a problem hiding this comment.
Remove the leftover
fiber migrate CLI annotation — it carries no documentation value in the committed codebase.
| return strings.ReplaceAll(frame.Function, "github.com/NdoleStudio/http-sms-manager/", "") | |
| } | |
| // fiber:context-methods migrated | |
| return strings.ReplaceAll(frame.Function, "github.com/NdoleStudio/http-sms-manager/", "") | |
| } |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Done in 01f3650 — removed the leftover // fiber:context-methods migrated annotation.
| APIKey string `json:"x-api-key" form:"x-api-key" query:"x-api-key"` | ||
| }{} | ||
|
|
||
| if err := c.BodyParser(&payload); err == nil && payload.APIKey != "" { | ||
| if err := c.Bind().Body(&payload); err == nil && payload.APIKey != "" { | ||
| return payload.APIKey | ||
| } | ||
|
|
||
| if err := c.QueryParser(&payload); err != nil { | ||
| if err := c.Bind().Query(&payload); err != nil { | ||
| return "" | ||
| } | ||
|
|
There was a problem hiding this comment.
Body read + Bind interaction in API key extraction
c.Bind().Body(&payload) in Fiber v3 is validated against the Content-Type header and will return an error for requests without a JSON body (e.g. GET with no Content-Type). The code silently discards that error and falls through to the query parser, which is intentional — but c.Bind().Body() in v3 may internally reset parts of the binder state on error. If a downstream handler also calls c.Bind().Body() on the same request, confirm that the binder does not retain any partial state from this early failed parse. Fiber v3's binder is per-request and body bytes are buffered in FastHTTP so re-reading is safe, but worth verifying with an integration test that sends an API key in the request body.
There was a problem hiding this comment.
Addressed in 01f3650. Guarded the early body parse with c.HasBody() so Bind().Body() is only attempted when a body is present, avoiding the failed-early-parse path entirely. Fiber v3's binder is per-request and FastHTTP buffers the body, so downstream handlers calling Bind().Body() re-read safely.
- Remove leftover 'fiber:context-methods migrated' annotation in otel_tracer.go - Guard body-based API key extraction with c.HasBody() to avoid attempting Bind().Body() on bodyless requests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Migrates the Go API (api/) from Fiber v2 to Fiber v3 (v3.3.0), updating routing, middleware, and request binding to match Fiber v3’s API changes.
Changes:
- Upgraded Fiber and related contrib dependencies (
otel,swaggo) and updated module sums. - Replaced
computeRoute(... )...route registration with ahandler.register(...)helper that usesrouter.Addto preserve middleware execution order. - Updated handler/middleware signatures from
*fiber.Ctxtofiber.Ctxand migrated parsing toc.Bind().Body/Query(...)plus CORS env splitting.
Reviewed changes
Copilot reviewed 33 out of 34 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| web/app/components/MessageThreadHeader.vue | UI tweak for select styling (width + primary color). |
| web/app/components/FirebaseAuth.vue | UI tweak to set primary color on auth fields. |
| api/pkg/telemetry/tracer.go | Updates tracer interface to accept Fiber v3 fiber.Ctx. |
| api/pkg/telemetry/otel_tracer.go | Migrates Fiber context access for tracing to v3 APIs. |
| api/pkg/services/webhook_service.go | Migrates Fiber import to v3. |
| api/pkg/services/marketting_service.go | Migrates Fiber import to v3. |
| api/pkg/services/integration_3cx_service.go | Migrates Fiber import to v3. |
| api/pkg/services/discord_service.go | Migrates Fiber import to v3. |
| api/pkg/middlewares/phone_api_key_auth_middleware.go | Migrates middleware signature to v3 fiber.Ctx. |
| api/pkg/middlewares/http_request_logger_middleware.go | Migrates middleware signature to v3 fiber.Ctx. |
| api/pkg/middlewares/bearer_auth_middleware.go | Migrates middleware signature to v3 fiber.Ctx. |
| api/pkg/middlewares/bearer_api_key_auth_middleware.go | Migrates middleware signature to v3 fiber.Ctx. |
| api/pkg/middlewares/authenticated_middlesare.go | Migrates middleware signature to v3 fiber.Ctx. |
| api/pkg/middlewares/api_key_auth_middleware.go | Migrates binding/parsing to c.Bind() and signature to v3. |
| api/pkg/handlers/webhook_handler.go | Updates route registration and binding/parsing for v3. |
| api/pkg/handlers/user_handler.go | Updates route registration and binding/parsing for v3. |
| api/pkg/handlers/phone_handler.go | Updates route registration and binding/parsing for v3. |
| api/pkg/handlers/phone_api_key_handler.go | Updates route registration and binding/parsing for v3. |
| api/pkg/handlers/message_thread_handler.go | Updates route registration and binding/parsing for v3. |
| api/pkg/handlers/message_send_schedule_handler.go | Updates route registration and binding/parsing for v3. |
| api/pkg/handlers/message_handler.go | Updates route registration and binding/parsing for v3. |
| api/pkg/handlers/lemonsqueezy_handler.go | Updates route registration and signature to v3 fiber.Ctx. |
| api/pkg/handlers/integration_3cx_handler.go | Updates route registration and binding/parsing for v3. |
| api/pkg/handlers/heartbeat_handler.go | Updates route registration and binding/parsing for v3. |
| api/pkg/handlers/handler.go | Introduces register(...) helper and migrates response helpers to v3 fiber.Ctx. |
| api/pkg/handlers/events_handler.go | Updates route registration and binding/parsing for v3. |
| api/pkg/handlers/discord_handler.go | Updates route registration, binding/parsing, and signatures for v3. |
| api/pkg/handlers/bulk_message_handler.go | Updates route registration and signature to v3 fiber.Ctx. |
| api/pkg/handlers/billing_handler.go | Updates route registration and binding/parsing for v3. |
| api/pkg/handlers/attachment_handler.go | Updates handler signature to v3 fiber.Ctx. |
| api/pkg/di/container.go | Updates Fiber middleware imports, CORS config types, and health handler signature. |
| api/pkg/di/config.go | Adds splitCommaEnv helper for Fiber v3 CORS []string fields. |
| api/go.mod | Bumps Fiber + contrib deps and related indirects. |
| api/go.sum | Updates module checksums for upgraded dependencies. |
Comments suppressed due to low confidence (1)
api/pkg/telemetry/otel_tracer.go:89
- Remove the leftover migration marker comment; it adds noise and doesn't provide actionable documentation.
| <div class="d-flex pt-2" style="width: 260px"> | ||
| <v-select | ||
| variant="outlined" | ||
| density="compact" | ||
| color="primary" |
| @@ -226,6 +227,7 @@ function handleError(error: unknown, isSocial = false) { | |||
| v-model="password" | |||
| label="Password" | |||
| type="password" | |||
| color="primary" | |||
| variant="outlined" | |||
| density="comfortable" | |||
| class="mb-2" | |||
Summary
Migrates the Go backend (\�pi/) from \gofiber/fiber/v2\ to \gofiber/fiber/v3\ (v3.3.0) using the official \iber migrate\ CLI plus manual fixups for breaking changes the tool couldn't fully handle.
Changes
outer.Add.
Verification
epositories, \�ntities, \discord)
Notes