A simple .env file loader for go(golang)
go get github.com/radulucut/dotenv
.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")
// ...
}
- Overrides existing variables
- Does not trim spaces
- Does not support comments