Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sbstnerhrdt/env
Environment variable handling in go
https://github.com/sbstnerhrdt/env
env environment environment-variables go golang
Last synced: about 1 month ago
JSON representation
Environment variable handling in go
- Host: GitHub
- URL: https://github.com/sbstnerhrdt/env
- Owner: SbstnErhrdt
- License: other
- Created: 2020-09-27T12:54:56.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-09T07:28:21.000Z (over 1 year ago)
- Last Synced: 2024-06-20T11:05:42.475Z (6 months ago)
- Topics: env, environment, environment-variables, go, golang
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Env
This is a small go module that helps with environment variables.
* Load environment files `.env`
* Provides fallback variables
* uses `slog`
* no dependenciesBased on https://github.com/joho/godotenv
## Installation
```
go get github.com/SbstnErhrdt/env
```## Usage
Put a `.env` file in the working directory.
This might look like this```
KEY=value1234
```In your `main()` funcion:
```go
func main() {
// load env
env.LoadEnvFiles() // reads the .env file in the working directory
...
}
```If no filename is provided, the file `.env` in the working directory is used.
### Load env files
Loads different env files. Prints warnings if the files not present.
```go
...
env.LoadEnvFiles(filenames ...string)
...
```Specify filename:
```go
...
env.LoadEnvFiles("production.enbv")
...
```### Fallback environment variables
Sets fallback variables for env variables.
```go
...
env.FallbackEnvVariable("environmentVariableKey", "fallbackValue")
...
```### Required variables check
Checks if there are **required** environment variables not set.
```go
...
env.CheckRequiredEnvironmentVariables("environmentVariableKey0", "environmentVariableKey1")
...
```### Optional variables check
Checks if there are optional environment variables not set.
```go
...
env.CheckOptionalEnvironmentVariables("environmentVariableKey0", "environmentVariableKey1")
...
```### Required variable check and return
Checks if there are optional environment variables not set.
```go
...
varName := env.RequiredEnvVariable("environmentVariableKey0")
...
```