Skip to content
A Go (golang) implementation of dotenv.
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
fixtures
.gitignore
.travis.yml
LICENSE
README.md
dotenv.go
dotenv_test.go
example_test.go

README.md

dotenv

build status Go Report Card godocs

A Go (golang) implementation of dotenv (inspired by: https://github.com/joho/godotenv).

Installation

As a Library:

go get github.com/alexsasharegan/dotenv

Usage

In your environment file (canonically named .env):

S3_BUCKET=YOURS3BUCKET
SECRET_KEY=YOURSECRETKEYGOESHERE

MESSAGE="A message containing important spaces."
ESCAPED='You can escape you\'re strings too.'

# A comment line that will be ignored
GIT_PROVIDER=github.com
LIB=${GIT_PROVIDER}/alexsasharegan/dotenv # variable interpolation (plus ignored trailing comment)

In your application:

package main

import (
    "fmt"
    "log"
    "os"

    "github.com/alexsasharegan/dotenv"
)

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

  s3Bucket := os.Getenv("S3_BUCKET")
  secretKey := os.Getenv("SECRET_KEY")

  fmt.Println(os.Getenv("MESSAGE"))
}

Documentation

https://godoc.org/github.com/alexsasharegan/dotenv

You can’t perform that action at this time.