A simple Go package to locate and load .env
files from any directory efficiently.
go get github.com/ignat-one/dotenv
package main
import (
"log"
"github.com/ignat-one/dotenv"
)
func main() {
err := dotenv.Load()
if err != nil {
log.Fatal(err)
}
// environment variables are now loaded
}
package main
import (
"log"
"github.com/ignat-one/dotenv"
)
func main() {
err := dotenv.Load(
dotenv.WithAnchorFile("your-anchor.file"),
dotenv.WithFilename("your.env"),
)
if err != nil {
log.Fatal(err)
}
// environment variables are now loaded
}
-
WithAnchorFile(filename string)
: Specify a custom anchor file to help locate the.env
file. The default value is"go.mod"
-
WithFilename(filename string)
: Specify a custom environment filename. The default value is".env"
Feel free to submit issues and enhancement requests.
This project is licensed under the MIT License - see the LICENSE file for details.