Skip to main content
Version: v2.x

EnvVar

EnvVar middleware for Fiber that can be used to expose environment variables with various options.

Signatures

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

Examples

Import the middleware package that is part of the Fiber web framework

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

After you initiate your Fiber app, you can use the following possibilities:

// Initialize default config
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"},
ExcludeVars: map[string]string{"excludeKey": ""},
}),
)
note

You will need to provide a path to use the envvar middleware.

Response

Http response contract:

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

Config

PropertyTypeDescriptionDefault
ExportVarsmap[string]stringExportVars specifies the environment variables that should be exported.nil
ExcludeVarsmap[string]stringExcludeVars specifies the environment variables that should not be exported.nil

Default Config

Config{}