A Go (golang) implementation of dotenv (inspired by: https://github.com/joho/godotenv).
As a Library:
go get github.com/alexsasharegan/dotenv
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"))
}