Skip to content

radulucut/dotenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dotenv

A simple .env file loader for go(golang)

Test

Install

go get github.com/radulucut/dotenv

Usage

.env

MY_VAR=some value
SECRET_KEY="s3cret"
SINGLE_QUOTE='some "value"'

main.go

package main

import (
	"log"
	"os"

	"github.com/radulucut/dotenv"
)

func main() {
	err := dotenv.Load(".env")
	if err != nil {
		log.Fatal("Error loading .env file")
	}

	myVar := os.Getenv("MY_VAR")
	secretKey := os.Getenv("SECRET_KEY")
	singleQuote := os.Getenv("SINGLE_QUOTE")

	// ...
}

Notes:

  • Overrides existing variables
  • Does not trim spaces
  • Does not support comments