All Projects → alexsasharegan → dotenv

alexsasharegan / dotenv

Licence: MIT License
A Go (golang) implementation of dotenv.

Programming Languages

go
31211 projects - #10 most used programming language

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].