github.com/gofiber/fiber/v2@v2.47.0/docs/api/middleware/envvar.md (about)

     1  ---
     2  id: envvar
     3  title: EnvVar
     4  ---
     5  
     6  EnvVar middleware for [Fiber](https://github.com/gofiber/fiber) that can be used to expose environment variables with various options.
     7  
     8  ## Signatures
     9  
    10  ```go
    11  func New(config ...Config) fiber.Handler
    12  ```
    13  
    14  ## Examples
    15  
    16  Import the middleware package that is part of the Fiber web framework
    17  
    18  ```go
    19  import (
    20    "github.com/gofiber/fiber/v2"
    21    "github.com/gofiber/fiber/v2/middleware/envvar"
    22  )
    23  ```
    24  
    25  After you initiate your Fiber app, you can use the following possibilities:
    26  
    27  ```go
    28  // Initialize default config
    29  app.Use("/expose/envvars", envvar.New())
    30  
    31  // Or extend your config for customization
    32  app.Use("/expose/envvars", envvar.New(
    33  	envvar.Config{
    34  		ExportVars:  map[string]string{"testKey": "", "testDefaultKey": "testDefaultVal"},
    35  		ExcludeVars: map[string]string{"excludeKey": ""},
    36  	}),
    37  )
    38  ```
    39  
    40  :::note
    41  You will need to provide a path to use the envvar middleware.
    42  :::
    43  
    44  ## Response
    45  
    46  Http response contract:
    47  ```
    48  {
    49    "vars": {
    50      "someEnvVariable": "someValue",
    51      "anotherEnvVariable": "anotherValue",
    52    }
    53  }
    54  
    55  ```
    56  
    57  ## Config
    58  
    59  ```go
    60  // Config defines the config for middleware.
    61  type Config struct {
    62      // ExportVars specifies the environment variables that should export
    63      ExportVars map[string]string
    64      // ExcludeVars specifies the environment variables that should not export
    65      ExcludeVars map[string]string
    66  }
    67  
    68  ```
    69  
    70  ## Default Config
    71  
    72  ```go
    73  Config{}
    74  ```