-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from mstrYoda/master
add envvar middleware docs
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Exposing Environment Variables Middleware | ||
|
||
EnvVar middleware for [Fiber](https://github.com/gofiber/fiber) that can be used to expose environment variables with various options. | ||
|
||
## Table of Contents | ||
|
||
* [Signatures](envvar.md#signatures) | ||
* [Examples](envvar.md#examples) | ||
* [Default Config](envvar.md#default-config) | ||
* [Custom Config](envvar.md#custom-config) | ||
* [Response](envvar.md#response) | ||
* [Config](envvar.md#config) | ||
* [Default Config](envvar.md#default-config-1) | ||
|
||
## Signatures | ||
|
||
```go | ||
func New(config ...Config) fiber.Handler | ||
``` | ||
|
||
## Examples | ||
|
||
First import the middleware from Fiber, | ||
|
||
```go | ||
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 | ||
|
||
```go | ||
app.Use("/expose/envvars", envvar.New()) | ||
``` | ||
|
||
### Custom Config | ||
|
||
```go | ||
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 | ||
|
||
```go | ||
// 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 | ||
|
||
```go | ||
Config{} | ||
``` |