ronantakizawa/codereview-bench huggingface dataset:
Repository: gofiber/fiber
File: listen_test.go (Go)

Code before:

// go test -run Test_Listen_Acme_TLS
func Test_Listen_Acme_TLS(t *testing.T) {
	dir, err := os.Getwd()
	require.NoError(t, err)
	dir, err = os.MkdirTemp(dir, "certs")
	require.NoError(t, err)
	defer os.RemoveAll(dir) //nolint:errcheck // ignore error

	// Certificate manager
	m := &autocert.Manager{
		Prompt: autocert.AcceptTOS,
		// Replace with your domain
		HostPolicy: autocert.HostWhitelist("example.com"),
		// Folder to store the certificates
		Cache: autocert.DirCache(dir),
		// Define the Client for test
		Client: &acme.Client{
			DirectoryURL: "https://acme-staging-v02.api.letsencrypt.org/directory",
		},
	}

	app := New()

	// invalid port
	require.Error(t, app.Listen(":99999", ListenConfig{
		DisableStartupMessage: true,
		AutoCertManager:       m,
	}))

	go func() {
		time.Sleep(1000 * time.Millisecond)
		assert.NoError(t, app.Shutdown())
	}()

	require.NoError(t, app.Listen(":0", ListenConfig{
		DisableStartupMessage: true,
		AutoCertManager:       m,
	}))
}

// go test -run Test_Listen_TLS_Prefork
func Test_Listen_TLS_Prefork(t *testing.T) {
	testPreforkMaster = true

	app := New()

	// invalid key file content
	require.Error(t, app.Listen(":0", ListenConfig{
		DisableStartupMessage: true,
		EnablePrefork:         true,

Review comment (bug):
@ReneWerner87 @efectn This is not failing, which may have exposed a bug in `Fiber`. That's an invalid port.

Code after:
				mu.Unlock()
			},
		})
	}()

	// Server readiness check
	for i := 0; i < 10; i++ {
		conn, err := ln.Dial()
		// To test a graceful shutdown timeout, do not close the connection.
		if err == nil {
			_ = conn
			break
		}
		// Wait a bit before retrying
		time.Sleep(100 * time.Millisecond)
		if i == 9 {
			t.Fatalf("Server did not become ready in time: %v", err)
		}
	}

	testCases := []struct {
		ExpectedErr             error
		ExpectedShutdownError   error
		ExpectedBody            string
		Time                    time.Duration
		ExpectedStatusCode      int
		ExpectedShutdownSuccess bool
	}{
		{
			Time:                    100 * time.Millisecond,
			ExpectedBody:            "example.com",
			ExpectedStatusCode:      StatusOK,
			ExpectedErr:             nil,
			ExpectedShutdownError:   nil,
			ExpectedShutdownSuccess: false,
		},
		{
			Time:                    3 * time.Second,
			ExpectedBody:            "",
			ExpectedStatusCode:      StatusOK,
			ExpectedErr:             fasthttputil.ErrInmemoryListenerClosed,
			ExpectedShutdownError:   context.DeadlineExceeded,
			ExpectedShutdownSuccess: false,
		},
	}

	for _, tc := range testCases {
		time.Sleep(tc.Time)

		req := fasthttp.AcquireRequest()
		req.SetRequestURI("http://example.com")
Repository: gofiber/fiber
File: ctx_test.go (Go)

Code before:
	tests := []string{"john", "doe", "hello", "fiber"}

	for _, test := range tests {
		var v string
		tt := test
		t.Run("test_genericParseTypeString", func(t *testing.T) {
			t.Parallel()
			require.Equal(t, tt, genericParseType(tt, v))
			require.Equal(t, tt, genericParseType[string](tt, v))
		})
	}
}

// go test -v -run=^$ -bench=Benchmark_GenericParseTypeInts -benchmem -count=4
func Benchmark_GenericParseTypeInts(b *testing.B) {
	type genericTypes[v GenericType] struct {
		value v
		str   string
	}

	ints := []genericTypes[int]{
		{
			value: 0,
			str:   "0",
		},
		{
			value: 1,
			str:   "1",
		},
		{
			value: 2,
			str:   "2",
		},
		{
			value: 3,
			str:   "3",
		},
		{
			value: 4,
			str:   "4",
		},
	}

	int8s := []genericTypes[int8]{
		{
			value: int8(0),
			str:   "0",
		},
		{
			value: int8(1),
			str:   "1",

Review comment (suggestion):
Add another handler here that just calls `return`, and test the output

Code after:
	require.Error(t, err)
	require.Nil(t, resp)

	// Test the no-response handler
	resp, err = app.Test(httptest.NewRequest(MethodGet, "/no-response", nil))
	require.NoError(t, err)
	require.NotNil(t, resp)
	require.Equal(t, StatusOK, resp.StatusCode)
	require.Equal(t, "0", resp.Header.Get("Content-Length"))
}

// go test -run Test_Ctx_DropWithMiddleware -v
func Test_Ctx_DropWithMiddleware(t *testing.T) {
	t.Parallel()

	app := New()

	// Middleware that calls Drop
	app.Use(func(c Ctx) error {
		err := c.Next()
		c.Set("X-Test", "test")
		return err
	})

	// Handler that calls Drop
	app.Get("/block-me", func(c Ctx) error {
		return c.Drop()
	})

	// Test the Drop method
	resp, err := app.Test(httptest.NewRequest(MethodGet, "/block-me", nil))
	require.Error(t, err)
	require.Nil(t, resp)
}

// go test -run Test_GenericParseTypeString
func Test_GenericParseTypeString(t *testing.T) {
	t.Parallel()

	tests := []string{"john", "doe", "hello", "fiber"}

	for _, test := range tests {
		var v string
		tt := test
		t.Run("test_genericParseTypeString", func(t *testing.T) {
			t.Parallel()
			require.Equal(t, tt, genericParseType(tt, v))
			require.Equal(t, tt, genericParseType[string](tt, v))
		})
	}
}
Repository: gofiber/fiber
File: ctx.go (Go)

Code before:
}

func (c *DefaultCtx) getMatched() bool {
	return c.matched
}

func (c *DefaultCtx) setIndexHandler(handler int) {
	c.indexHandler = handler
}

func (c *DefaultCtx) setIndexRoute(route int) {
	c.indexRoute = route
}

func (c *DefaultCtx) setMatched(matched bool) {
	c.matched = matched
}

func (c *DefaultCtx) setRoute(route *Route) {
	c.route = route
}

func (c *DefaultCtx) Drop() error {
	//nolint:wrapcheck // This must not be wrapped
	return c.RequestCtx().Conn().Close()
}


Review comment (suggestion):
Please add a doc comment here explaining what `Drop()` does. You can use the same description you wrote for the feature in `docs/api/ctx.md`.

Code after:
}

func (c *DefaultCtx) getMatched() bool {
	return c.matched
}

func (c *DefaultCtx) setIndexHandler(handler int) {
	c.indexHandler = handler
}

func (c *DefaultCtx) setIndexRoute(route int) {
	c.indexRoute = route
}

func (c *DefaultCtx) setMatched(matched bool) {
	c.matched = matched
}

func (c *DefaultCtx) setRoute(route *Route) {
	c.route = route
}

// Drop closes the underlying connection without sending any response headers or body.
// This can be useful for silently terminating client connections, such as in DDoS mitigation
// or when blocking access to sensitive endpoints.
func (c *DefaultCtx) Drop() error {
	//nolint:wrapcheck // error wrapping is avoided to keep the operation lightweight and focused on connection closure.
	return c.RequestCtx().Conn().Close()
}
Repository: gofiber/fiber
File: ctx_test.go (Go)

Code before:
		return nil
	})

	// Test the Drop method
	resp, err := app.Test(httptest.NewRequest(MethodGet, "/block-me", nil))
	require.Error(t, err)
	require.Nil(t, resp)

	// Test the no-response handler
	resp, err = app.Test(httptest.NewRequest(MethodGet, "/no-response", nil))
	require.NoError(t, err)
	require.NotNil(t, resp)
	require.Equal(t, StatusOK, resp.StatusCode)
	require.Equal(t, "0", resp.Header.Get("Content-Length"))
}

// go test -run Test_Ctx_DropWithMiddleware -v
func Test_Ctx_DropWithMiddleware(t *testing.T) {
	t.Parallel()

	app := New()

	// Middleware that calls Drop
	app.Use(func(c Ctx) error {
		err := c.Next()
		c.Response().Header.Set("X-Test", "test")
		return err
	})

	// Handler that calls Drop
	app.Get("/block-me", func(c Ctx) error {
		return c.Drop()
	})

	// Test the Drop method
	resp, err := app.Test(httptest.NewRequest(MethodGet, "/block-me", nil))
	require.Error(t, err)
	require.Nil(t, resp)
	require.Panics(t, func() {
		// panic: cannot read response body after it was closed
		require.Equal(t, "test", resp.Header.Get("X-Test"))
	})
}

// go test -run Test_GenericParseTypeString
func Test_GenericParseTypeString(t *testing.T) {
	t.Parallel()

	tests := []string{"john", "doe", "hello", "fiber"}

	for _, test := range tests {

Review comment (suggestion):
Could we rewrite this as the following for readability?

```go
c.Set("X-Test", "test")
```

Code after:
		return nil
	})

	// Test the Drop method
	resp, err := app.Test(httptest.NewRequest(MethodGet, "/block-me", nil))
	require.Error(t, err)
	require.Nil(t, resp)

	// Test the no-response handler
	resp, err = app.Test(httptest.NewRequest(MethodGet, "/no-response", nil))
	require.NoError(t, err)
	require.NotNil(t, resp)
	require.Equal(t, StatusOK, resp.StatusCode)
	require.Equal(t, "0", resp.Header.Get("Content-Length"))
}

// go test -run Test_Ctx_DropWithMiddleware -v
func Test_Ctx_DropWithMiddleware(t *testing.T) {
	t.Parallel()

	app := New()

	// Middleware that calls Drop
	app.Use(func(c Ctx) error {
		err := c.Next()
		c.Set("X-Test", "test")
		return err
	})

	// Handler that calls Drop
	app.Get("/block-me", func(c Ctx) error {
		return c.Drop()
	})

	// Test the Drop method
	resp, err := app.Test(httptest.NewRequest(MethodGet, "/block-me", nil))
	require.Error(t, err)
	require.Nil(t, resp)
}

// go test -run Test_GenericParseTypeString
func Test_GenericParseTypeString(t *testing.T) {
	t.Parallel()

	tests := []string{"john", "doe", "hello", "fiber"}

	for _, test := range tests {
		var v string
		tt := test
		t.Run("test_genericParseTypeString", func(t *testing.T) {
			t.Parallel()
Repository: gofiber/fiber
File: ctx_test.go (Go)

Code before:
	require.Equal(t, "0", resp.Header.Get("Content-Length"))
}

// go test -run Test_Ctx_DropWithMiddleware -v
func Test_Ctx_DropWithMiddleware(t *testing.T) {
	t.Parallel()

	app := New()

	// Middleware that calls Drop
	app.Use(func(c Ctx) error {
		err := c.Next()
		c.Response().Header.Set("X-Test", "test")
		return err
	})

	// Handler that calls Drop
	app.Get("/block-me", func(c Ctx) error {
		return c.Drop()
	})

	// Test the Drop method
	resp, err := app.Test(httptest.NewRequest(MethodGet, "/block-me", nil))
	require.Error(t, err)
	require.Nil(t, resp)
	require.Panics(t, func() {
		// panic: cannot read response body after it was closed
		require.Equal(t, "test", resp.Header.Get("X-Test"))
	})
}

// go test -run Test_GenericParseTypeString
func Test_GenericParseTypeString(t *testing.T) {
	t.Parallel()

	tests := []string{"john", "doe", "hello", "fiber"}

	for _, test := range tests {
		var v string
		tt := test
		t.Run("test_genericParseTypeString", func(t *testing.T) {
			t.Parallel()
			require.Equal(t, tt, genericParseType(tt, v))
			require.Equal(t, tt, genericParseType[string](tt, v))
		})
	}
}

// go test -v -run=^$ -bench=Benchmark_GenericParseTypeInts -benchmem -count=4
func Benchmark_GenericParseTypeInts(b *testing.B) {
	type genericTypes[v GenericType] struct {

Review comment (suggestion):
I'm not sure if this `require.Panics` is required.

When `resp == nil`, any operation/access done on it should presumably panic due to `invalid memory address or nil pointer dereference`.

I think it should be safe to remove it if we have `require.Nil(t, resp)` above.

Code after:
	require.Equal(t, "0", resp.Header.Get("Content-Length"))
}

// go test -run Test_Ctx_DropWithMiddleware -v
func Test_Ctx_DropWithMiddleware(t *testing.T) {
	t.Parallel()

	app := New()

	// Middleware that calls Drop
	app.Use(func(c Ctx) error {
		err := c.Next()
		c.Set("X-Test", "test")
		return err
	})

	// Handler that calls Drop
	app.Get("/block-me", func(c Ctx) error {
		return c.Drop()
	})

	// Test the Drop method
	resp, err := app.Test(httptest.NewRequest(MethodGet, "/block-me", nil))
	require.Error(t, err)
	require.Nil(t, resp)
}

// go test -run Test_GenericParseTypeString
func Test_GenericParseTypeString(t *testing.T) {
	t.Parallel()

	tests := []string{"john", "doe", "hello", "fiber"}

	for _, test := range tests {
		var v string
		tt := test
		t.Run("test_genericParseTypeString", func(t *testing.T) {
			t.Parallel()
			require.Equal(t, tt, genericParseType(tt, v))
			require.Equal(t, tt, genericParseType[string](tt, v))
		})
	}
}

// go test -v -run=^$ -bench=Benchmark_GenericParseTypeInts -benchmem -count=4
func Benchmark_GenericParseTypeInts(b *testing.B) {
	type genericTypes[v GenericType] struct {
		value v
		str   string
	}
Repository: gofiber/fiber
File: middleware/cache/cache.go (Go)

Code before:
				}
				// Set Cache-Control header if enabled
				if cfg.CacheControl {
					maxAge := strconv.FormatUint(e.exp-ts, 10)
					c.Set(fiber.HeaderCacheControl, "public, max-age="+maxAge)
				}

				c.Set(cfg.CacheHeader, cacheHit)

				mux.Unlock()

				// Return response
				return nil
			}
		}

		// make sure we're not blocking concurrent requests - do unlock
		mux.Unlock()

		// Continue stack, return err to Fiber if exist
		if err := c.Next(); err != nil {
			return err
		}

		// Don't cache response if status code is not cacheable
		if !slices.Contains(cacheableStatusCodes, c.Response().StatusCode()) {
			c.Set(cfg.CacheHeader, cacheUnreachable)
			return nil
		}

		// lock entry back and unlock on finish
		mux.Lock()
		defer mux.Unlock()

		// Don't cache response if Next returns true
		if cfg.Next != nil && cfg.Next(c) {
			c.Set(cfg.CacheHeader, cacheUnreachable)
			return nil
		}

		// Don't try to cache if body won't fit into cache
		bodySize := uint(len(c.Response().Body()))
		if cfg.MaxBytes > 0 && bodySize > cfg.MaxBytes {
			c.Set(cfg.CacheHeader, cacheUnreachable)
			return nil
		}

		// Remove oldest to make room for new
		if cfg.MaxBytes > 0 {
			for storedBytes+bodySize > cfg.MaxBytes {
				key, size := heap.removeFirst()

Review comment (performance):
With the map, this can be replaced with:

```go
if !cacheableStatusCodes[c.Response().StatusCode()] {
    c.Set(cfg.CacheHeader, cacheUnreachable)
    return nil
}
```

Code after:
				c.Response().SetBodyRaw(e.body)
				c.Response().SetStatusCode(e.status)
				c.Response().Header.SetContentTypeBytes(e.ctype)
				if len(e.cencoding) > 0 {
					c.Response().Header.SetBytesV(fiber.HeaderContentEncoding, e.cencoding)
				}
				for k, v := range e.headers {
					c.Response().Header.SetBytesV(k, v)
				}
				// Set Cache-Control header if enabled
				if cfg.CacheControl {
					maxAge := strconv.FormatUint(e.exp-ts, 10)
					c.Set(fiber.HeaderCacheControl, "public, max-age="+maxAge)
				}

				c.Set(cfg.CacheHeader, cacheHit)

				mux.Unlock()

				// Return response
				return nil
			}
		}

		// make sure we're not blocking concurrent requests - do unlock
		mux.Unlock()

		// Continue stack, return err to Fiber if exist
		if err := c.Next(); err != nil {
			return err
		}

		// Don't cache response if status code is not cacheable
		if !cacheableStatusCodes[c.Response().StatusCode()] {
			c.Set(cfg.CacheHeader, cacheUnreachable)
			return nil
		}

		// lock entry back and unlock on finish
		mux.Lock()
		defer mux.Unlock()

		// Don't cache response if Next returns true
		if cfg.Next != nil && cfg.Next(c) {
			c.Set(cfg.CacheHeader, cacheUnreachable)
			return nil
		}

		// Don't try to cache if body won't fit into cache
		bodySize := uint(len(c.Response().Body()))
		if cfg.MaxBytes > 0 && bodySize > cfg.MaxBytes {
Repository: gofiber/fiber
File: middleware/logger/default_logger.go (Go)

Code before:
package logger

import (
	"fmt"
	"io"
	"os"
	"strconv"

	"github.com/gofiber/fiber/v3"
	"github.com/gofiber/utils/v2"
	"github.com/mattn/go-colorable"
	"github.com/mattn/go-isatty"
	"github.com/valyala/bytebufferpool"
)

// default logger for fiber
func defaultLoggerInstance(c fiber.Ctx, data *Data, cfg Config) error {
	// Check if Filter is defined and call it
	if cfg.Filter != nil && !cfg.Filter(c) {
		return nil // Skip logging if Filter returns false
	}

	// Alias colors
	colors := c.App().Config().ColorScheme

	// Get new buffer
	buf := bytebufferpool.Get()

	// Default output when no custom Format or io.Writer is given
	if cfg.Format == defaultFormat {
		// Format error if exist
		formatErr := ""
		if cfg.enableColors {
			if data.ChainErr != nil {
				formatErr = colors.Red + " | " + data.ChainErr.Error() + colors.Reset
			}
			buf.WriteString(
				fmt.Sprintf("%s |%s %3d %s| %13v | %15s |%s %-7s %s| %-"+data.ErrPaddingStr+"s %s\n",
					data.Timestamp.Load().(string), //nolint:forcetypeassert,errcheck // Timestamp is always a string
					statusColor(c.Response().StatusCode(), colors), c.Response().StatusCode(), colors.Reset,
					data.Stop.Sub(data.Start),
					c.IP(),
					methodColor(c.Method(), colors), c.Method(), colors.Reset,
					c.Path(),

Review comment (bug):
@JIeJaitt I think this is wrong. It should be:

```go
if cfg.Filter != nil && cfg.Filter(c)
```
In the current implementation it's using a negated approach which is not user friendly.

Code after:
package logger

import (
	"fmt"
	"io"
	"os"
	"strconv"

	"github.com/gofiber/fiber/v3"
	"github.com/gofiber/utils/v2"
	"github.com/mattn/go-colorable"
	"github.com/mattn/go-isatty"
	"github.com/valyala/bytebufferpool"
)

// default logger for fiber
func defaultLoggerInstance(c fiber.Ctx, data *Data, cfg Config) error {
	// Check if Skip is defined and call it.
	// Now, if Skip(c) == true, we SKIP logging:
	if cfg.Skip != nil && cfg.Skip(c) {
		return nil // Skip logging if Skip returns true
	}

	// Alias colors
	colors := c.App().Config().ColorScheme

	// Get new buffer
	buf := bytebufferpool.Get()

	// Default output when no custom Format or io.Writer is given
	if cfg.Format == defaultFormat {
		// Format error if exist
		formatErr := ""
		if cfg.enableColors {
			if data.ChainErr != nil {
				formatErr = colors.Red + " | " + data.ChainErr.Error() + colors.Reset
			}
			buf.WriteString(
				fmt.Sprintf("%s |%s %3d %s| %13v | %15s |%s %-7s %s| %-"+data.ErrPaddingStr+"s %s\n",
					data.Timestamp.Load().(string), //nolint:forcetypeassert,errcheck // Timestamp is always a string
					statusColor(c.Response().StatusCode(), colors), c.Response().StatusCode(), colors.Reset,
					data.Stop.Sub(data.Start),
					c.IP(),
					methodColor(c.Method(), colors), c.Method(), colors.Reset,
Repository: gofiber/fiber
File: middleware/logger/default_logger.go (Go)

Code before:
package logger

import (
	"fmt"
	"io"
	"os"
	"strconv"

	"github.com/gofiber/fiber/v3"
	"github.com/gofiber/utils/v2"
	"github.com/mattn/go-colorable"
	"github.com/mattn/go-isatty"
	"github.com/valyala/bytebufferpool"
)

// default logger for fiber
func defaultLoggerInstance(c fiber.Ctx, data *Data, cfg Config) error {
	// Check if Filter is defined and call it.
	// Now, if Filter(c) == true, we SKIP logging:
	if cfg.Skip != nil && cfg.Skip(c) {
		return nil // Skip logging if Filter returns true
	}

	// Alias colors
	colors := c.App().Config().ColorScheme

	// Get new buffer
	buf := bytebufferpool.Get()

	// Default output when no custom Format or io.Writer is given
	if cfg.Format == defaultFormat {
		// Format error if exist
		formatErr := ""
		if cfg.enableColors {
			if data.ChainErr != nil {
				formatErr = colors.Red + " | " + data.ChainErr.Error() + colors.Reset
			}
			buf.WriteString(
				fmt.Sprintf("%s |%s %3d %s| %13v | %15s |%s %-7s %s| %-"+data.ErrPaddingStr+"s %s\n",
					data.Timestamp.Load().(string), //nolint:forcetypeassert,errcheck // Timestamp is always a string
					statusColor(c.Response().StatusCode(), colors), c.Response().StatusCode(), colors.Reset,
					data.Stop.Sub(data.Start),
					c.IP(),
					methodColor(c.Method(), colors), c.Method(), colors.Reset,
					c.Path(),
					formatErr,
				),

Review comment (suggestion):
```suggestion
	// Check if Skip is defined and call it.
	// Now, if Skip(c) == true, we SKIP logging:
	if cfg.Skip != nil && cfg.Skip(c) {
		return nil // Skip logging if Skip returns true
	}
```

Code after:
package logger

import (
	"fmt"
	"io"
	"os"
	"strconv"

	"github.com/gofiber/fiber/v3"
	"github.com/gofiber/utils/v2"
	"github.com/mattn/go-colorable"
	"github.com/mattn/go-isatty"
	"github.com/valyala/bytebufferpool"
)

// default logger for fiber
func defaultLoggerInstance(c fiber.Ctx, data *Data, cfg Config) error {
	// Check if Skip is defined and call it.
	// Now, if Skip(c) == true, we SKIP logging:
	if cfg.Skip != nil && cfg.Skip(c) {
		return nil // Skip logging if Skip returns true
	}

	// Alias colors
	colors := c.App().Config().ColorScheme

	// Get new buffer
	buf := bytebufferpool.Get()

	// Default output when no custom Format or io.Writer is given
	if cfg.Format == defaultFormat {
		// Format error if exist
		formatErr := ""
		if cfg.enableColors {
			if data.ChainErr != nil {
				formatErr = colors.Red + " | " + data.ChainErr.Error() + colors.Reset
			}
			buf.WriteString(
				fmt.Sprintf("%s |%s %3d %s| %13v | %15s |%s %-7s %s| %-"+data.ErrPaddingStr+"s %s\n",
					data.Timestamp.Load().(string), //nolint:forcetypeassert,errcheck // Timestamp is always a string
					statusColor(c.Response().StatusCode(), colors), c.Response().StatusCode(), colors.Reset,
					data.Stop.Sub(data.Start),
					c.IP(),
					methodColor(c.Method(), colors), c.Method(), colors.Reset,
					c.Path(),
					formatErr,
				),
Repository: gofiber/fiber
File: middleware/logger/format.go (Go)

Code before:
package logger

const (
	// Fiber's default logger `
	FormatDefault = "[${time}] ${ip} ${status} - ${latency} ${method} ${path} ${error}\n"
	// Common log format
	FormatCommonLog = "${ip} - - [${time}] \"${method} ${url} ${protocol}\" ${status} ${bytesSent}\n"
	// Combined log format
	FormatCombined = "${ip} - - [${time}] \"${method} ${url} ${protocol}\" ${status} ${bytesSent} \"${referer}\" \"${ua}\"\n"
	// JSON log formats
	FormatJSON = "{\"time\":\"${time}\",\"ip\":\"${ip}\",\"method\":\"${method}\",\"url\":\"${url}\",\"status\":${status},\"bytesSent\":${bytesSent}}\n"
	// ECS Log format
	FormatECS = "{\"@timestamp\":\"${time}\",\"ecs\":{\"version\":\"1.6.0\"},\"client\":{\"ip\":\"${ip}\"},\"http\":{\"request\":{\"method\":\"${method}\",\"url\":\"${url}\",\"protocol\":\"${protocol}\"},\"response\":{\"status_code\":${status},\"body\":{\"bytes\":${bytesSent}}}},\"log\":{\"level\":\"INFO\",\"logger\":\"fiber\"},\"message\":\"${method} ${url} responded with ${status}\"}\n"
)

// LoggerConfig provides a mapping of predefined log format configurations
// that can be used to customize log output styles. The map keys represent
// different log format types, and the values are the corresponding format strings.
var LoggerConfig = map[string]string{
	"default":  FormatDefault,
	"common":   FormatCommonLog,
	"combined": FormatCombined,
	"json":     FormatJSON,
	"ecs":      FormatECS,
}


Review comment (suggestion):
We should get rid of this. It's prone to errors and confusion about which options are available. The const above in this file are a better approach

Code after:
package logger

const (
	// Fiber's default logger
	DefaultFormat = "[${time}] ${ip} ${status} - ${latency} ${method} ${path} ${error}\n"
	// Apache Common Log Format (CLF)
	CommonFormat = "${ip} - - [${time}] \"${method} ${url} ${protocol}\" ${status} ${bytesSent}\n"
	// Apache Combined Log Format
	CombinedFormat = "${ip} - - [${time}] \"${method} ${url} ${protocol}\" ${status} ${bytesSent} \"${referer}\" \"${ua}\"\n"
	// JSON log formats
	JSONFormat = "{\"time\":\"${time}\",\"ip\":\"${ip}\",\"method\":\"${method}\",\"url\":\"${url}\",\"status\":${status},\"bytesSent\":${bytesSent}}\n"
	// Elastic Common Schema (ECS) Log Format
	ECSFormat = "{\"@timestamp\":\"${time}\",\"ecs\":{\"version\":\"1.6.0\"},\"client\":{\"ip\":\"${ip}\"},\"http\":{\"request\":{\"method\":\"${method}\",\"url\":\"${url}\",\"protocol\":\"${protocol}\"},\"response\":{\"status_code\":${status},\"body\":{\"bytes\":${bytesSent}}}},\"log\":{\"level\":\"INFO\",\"logger\":\"fiber\"},\"message\":\"${method} ${url} responded with ${status}\"}\n"
)