Files
fiber/docs/middleware/envvar.md
Juan Calderon-PerezGitHubcoderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
e4737ee937 📒 docs: Full audit of documentation (#3717)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-08-29 12:34:19 +02:00

1.4 KiB

id
id
envvar

EnvVar

EnvVar middleware for Fiber exposes environment variables with configurable options.

Signatures

func New(config ...Config) fiber.Handler

Examples

Import the middleware package:

import (
    "github.com/gofiber/fiber/v3"
    "github.com/gofiber/fiber/v3/middleware/envvar"
)

Once your Fiber app is initialized, configure the middleware as shown:

// Initialize default config (exports no variables)
app.Use("/expose/envvars", envvar.New())

// Or extend your config for customization
app.Use("/expose/envvars", envvar.New(
    envvar.Config{
        ExportVars: map[string]string{"testKey": "", "testDefaultKey": "testDefaultVal"},
    }),
)

:::note Mount the middleware on a path; it cannot be used without one. :::

Response

Sample response:

{
  "vars": {
    "someEnvVariable": "someValue",
    "anotherEnvVariable": "anotherValue"
  }
}

Config

Property Type Description Default
ExportVars map[string]string ExportVars lists the environment variables to expose. nil

Default Config

Config{}
// Exports no environment variables