Skip to content

refactor(api): migrate backend from Fiber v2 to v3#928

Merged
AchoArnold merged 4 commits into
mainfrom
AchoArnold/fiber-v3-migration
Jun 25, 2026
Merged

refactor(api): migrate backend from Fiber v2 to v3#928
AchoArnold merged 4 commits into
mainfrom
AchoArnold/fiber-v3-migration

Conversation

@AchoArnold

Copy link
Copy Markdown
Member

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

  • Bump to Fiber v3.3.0 in \go.mod/\go.sum.
  • Swap contrib deps:
    • \gofiber/contrib/otelfiber\ -> \gofiber/contrib/v3/otel\ (aliased \otelfiber\ to avoid clashing with \go.opentelemetry.io/otel)
    • \gofiber/swagger\ -> \gofiber/contrib/v3/swaggo\
  • Routing: v3 changed the signature to \Get(path, handler, ...middleware). Replaced the \computeRoute(...)...\ spread across ~50 call sites with a new \handler.register()\ helper that preserves [middlewares..., route]\ execution order via
    outer.Add.
  • CORS: v3 \cors.Config\ fields are now []string; added a \splitCommaEnv()\ helper.
  • Context: *fiber.Ctx\ -> \ iber.Ctx\ across handlers and middlewares.

Verification

  • \go build ./...\ passes
  • Unit tests pass (\services,
    epositories, \�ntities, \discord)

Notes

  • Handler tests are integration tests hitting \http://localhost:8000\ (live server), not in-process — out of scope for CI here.
  • Pre-existing \stacktrace\ printf \go vet\ warnings are unrelated to this migration.

AchoArnold and others added 2 commits June 24, 2026 23:05
- 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>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

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-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Migrates the Go backend from gofiber/fiber/v2 to gofiber/fiber/v3 (v3.3.0), swapping contrib packages for OTel and Swagger, updating all handler and middleware signatures from *fiber.Ctx to the v3 fiber.Ctx interface, and adapting the routing, binding, and CORS configuration to the new API.

  • Routing: replaces the old computeRoute(middlewares, handler)... spread with a register() helper that calls the v3 router.Add([]string{method}, path, any, ...any) signature, preserving middleware-first execution order across ~50 call sites.
  • Binding: migrates c.BodyParserc.Bind().Body() and c.QueryParserc.Bind().Query() throughout all handlers; the c.UserContext() call in the OTel tracer is correctly replaced with c.Context().
  • CORS: AllowOrigins/Headers/Methods/ExposeHeaders are now []string (Fiber v3 requirement) populated via a new splitCommaEnv() helper; two minor Vue UI tweaks (color theming, width) are bundled in the PR.

Confidence Score: 4/5

The 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

Filename Overview
api/pkg/handlers/handler.go Replaces computeRoute spread with register() helper using Fiber v3's Add([]string, path, any, ...any) signature; all response method signatures updated from *fiber.Ctx to fiber.Ctx.
api/pkg/di/container.go Swaps Fiber v2 imports for v3, replaces gofiber/swagger with gofiber/contrib/v3/swaggo, migrates CORS config from comma-string fields to []string via splitCommaEnv.
api/pkg/di/config.go Adds splitCommaEnv helper for Fiber v3 CORS []string config fields; handles trimming and empty-entry filtering correctly.
api/pkg/telemetry/otel_tracer.go Correctly replaces c.UserContext() with c.Context() for OTel; contains a leftover migration CLI annotation that should be removed.
api/pkg/middlewares/api_key_auth_middleware.go Migrates to Bind().Body()/Bind().Query(); two-phase key extraction should work correctly but integration test coverage for the body-key path is advisable.
api/pkg/handlers/message_handler.go All handler signatures and binding calls correctly migrated to Fiber v3 API.
api/go.mod Bumps to gofiber/fiber v3.3.0 and swaps contrib packages for their v3 equivalents.
api/pkg/telemetry/tracer.go Updates Tracer interface to use fiber.Ctx interface instead of *fiber.Ctx pointer.
web/app/components/FirebaseAuth.vue Minor UI tweak: adds color=primary to form fields — unrelated to backend migration.
web/app/components/MessageThreadHeader.vue Cosmetic change: widens phone selector from 245px to 260px and adds color=primary.

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
Loading
%%{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
Loading

Reviews (1): Last reviewed commit: "refactor(api): migrate backend from Fibe..." | Re-trigger Greptile

Comment thread api/pkg/telemetry/otel_tracer.go Outdated
Comment on lines +85 to +88
return strings.ReplaceAll(frame.Function, "github.com/NdoleStudio/http-sms-manager/", "")
}

// fiber:context-methods migrated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Remove the leftover fiber migrate CLI annotation — it carries no documentation value in the committed codebase.

Suggested change
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!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 01f3650 — removed the leftover // fiber:context-methods migrated annotation.

Comment on lines 47 to 57
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 ""
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a handler.register(...) helper that uses router.Add to preserve middleware execution order.
  • Updated handler/middleware signatures from *fiber.Ctx to fiber.Ctx and migrated parsing to c.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.

Comment on lines +86 to +90
<div class="d-flex pt-2" style="width: 260px">
<v-select
variant="outlined"
density="compact"
color="primary"
Comment on lines 216 to 233
@@ -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"
@AchoArnold AchoArnold merged commit f785f62 into main Jun 25, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants