fiber/middleware/envvar
leonklingele 167a8b5e94
🚀 Feature: Add and apply more stricter golangci-lint linting rules (#2286)
* golangci-lint: add and apply more stricter linting rules

* github: drop security workflow now that we use gosec linter inside golangci-lint

* github: use official golangci-lint CI linter

* Add editorconfig and gitattributes file
2023-01-27 09:01:37 +01:00
..
README.md 🐛 Fix: EnvVar middleware parses base64 incorrectly (#2069) 2022-09-03 19:03:51 +02:00
envvar.go 🚀 Feature: Add and apply more stricter golangci-lint linting rules (#2286) 2023-01-27 09:01:37 +01:00
envvar_test.go 🚀 Feature: Add and apply more stricter golangci-lint linting rules (#2286) 2023-01-27 09:01:37 +01:00

README.md

Exposing Environment Variables Middleware

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

Table of Contents

Signatures

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

Examples

First import the middleware from Fiber,

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

Then create a Fiber app with app := fiber.New().

Note: You need to provide a path to use envvar middleware.

Default Config

app.Use("/expose/envvars", envvar.New())

Custom Config

app.Use("/expose/envvars", envvar.New(
	envvar.Config{
		ExportVars:  map[string]string{"testKey": "", "testDefaultKey": "testDefaultVal"},
		ExcludeVars: map[string]string{"excludeKey": ""},
	}),
)

Response

Http response contract:

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

Config

// Config defines the config for middleware.
type Config struct {
	// ExportVars specifies the environment variables that should export
	ExportVars map[string]string
	// ExcludeVars specifies the environment variables that should not export
	ExcludeVars map[string]string
}

Default Config

Config{}