View the documentation
go get -u github.com/nathanburkett/env
Reading an environmental file via Reader
package main
import (
"fmt"
"log"
"github.com/nathanburkett/env"
"os"
)
func main() {
pwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
readEnv(pwd)
}
func readEnv(workingDir string) {
envPath := fmt.Sprintf("%s/.env", workingDir)
file, err := os.Open(envPath)
if err != nil {
log.Panic(err)
}
defer file.Close()
env.NewReader(file).Read()
}
Using Must()
package main
import (
"github.com/jmoiron/sqlx"
"github.com/nathanburkett/env"
"log"
)
func main() {
_, err := sqlx.Open("mysql", env.Must("DB_DSN"))
if err != nil {
log.Fatal(err)
}
// ...
}
On MacOS you can install or upgrade to the latest released version with Homebrew:
brew install dep
brew upgrade dep
On other platforms you can use the install.sh script:
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
make install -B
make coverage -B
Copyright (c) 2018 Nathan Burkett
Licensed under the MIT License