Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/roger-king/go-getenv
a simple getenv wrapper to allow for default environment. inspired by python's os.getenv("ENV", default)
https://github.com/roger-king/go-getenv
dotenv environment-variables getenv go
Last synced: 18 days ago
JSON representation
a simple getenv wrapper to allow for default environment. inspired by python's os.getenv("ENV", default)
- Host: GitHub
- URL: https://github.com/roger-king/go-getenv
- Owner: roger-king
- Created: 2020-05-17T19:26:20.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-17T20:42:56.000Z (over 4 years ago)
- Last Synced: 2024-11-04T09:09:17.103Z (about 2 months ago)
- Topics: dotenv, environment-variables, getenv, go
- Language: Go
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-getenv
A simple getenv utility to support default values to be set. This is a port from python's `os.getenv("ENV_KEY", "default)`. This utility function will do a few things:
1. Return the passed default value (with a logging message).
2. Return the environment variable set over the default value
3. Panic if the Environment variable does not exist and no default value set.# Installation
Installation is done using the go get command:
```
go get -u github.com/roger-king/go-getenv
```# Usage
Using the utility function is simple. We call the function and pass in as the first arg the `Environment Variable Key` and the `getenv.String("some-string")`.
```
import "github.com/roger-king/go-getenv"port := getenv.EnvOrDefault("PORT", getenv.String(":5000"))
```## Why `getenv.String("some-string")`
I decided to create a `String()` function because I want to support the ability to pass `nil` as the second or default argument.