Skip to content

🐛 [Bug]: Missing ContextKey in requestid middleware configuration #2732

@gopkg-dev

Description

@gopkg-dev

Bug Description

This is my fix:

#2731

-	if cfg.ContextKey == "" {
+	if cfg.ContextKey == nil || cfg.ContextKey == "" {
		cfg.ContextKey = ConfigDefault.ContextKey
	}

The fix checks if cfg.ContextKey is either nil or an empty string before assigning the default value ConfigDefault.ContextKey. This ensures that the ContextKey is not missing or empty.

How to Reproduce

package main

import (
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/requestid"
	"github.com/gofiber/fiber/v2/utils"
)
import "log"

func main() {
	app := fiber.New()

	// Steps to reproduce
	app.Use(requestid.New(requestid.Config{
		// ContextKey is currently nil
		Generator: utils.UUID,
	}))


	log.Fatal(app.Listen(":3000"))
}

Expected Behavior

...

Fiber Version

v2.51.0

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions