Skip to content

BolajiOlajide/go-env-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go-Env-Utils

A Go (golang) port of the node env-utils project.

Easily Get Environment Variables

Install

go get github.com/BolajiOlajide/go-env-utils

Methods

GetEnvVar

gets an environment variable

import "github.com/BolajiOlajide/go-env-utils"

// load .env file and fail silently if it doesn't exist
_ := env.InitializeEnv()
PORT := env.GetEnvVar("PORT", nil)

You can force the value to be a boolean

options := env.Options{
  Boolean: true
}
PORT := env.GetEnvVar("PORT", options)

And if your env variable is a comma separated string you can get back an array instead

options := env.Options{
  CommaSeparated: true
}
PORT := env.GetEnvVar("PORT", options)

You can also set a fallback value for development mode

options := env.Options{
  DevDefault: "1234"
}
PORT := env.GetEnvVar("PORT", options)