Load application environment variables from a .env
file into the current process.
// Usage 1: Type Safe Env Config
import (
dotenv "github.com/go-zoox/dotenv"
)
type Config struct {
Host string `env:"HOST" default:"0.0.0.0"`
Port int `env:"PORT" default:"8080"`
DatabaseUrl string `env:"DATABASE_URL", required:"true"`
Email string `env:"EMAIL"`
}
var config Config
if err := dotenv.Load(&config); err != nil {
panic(err)
}
// Usage 2: Auto Load .env To OS
import (
"os"
_ "github.com/go-zoox/dotenv"
)
fmt.Println("env:", os.Get("FROM_DOT_ENV"))
- joho/godotenv - dot env file
- ilyakaznacheev/cleanenv - struct tag
- JeremyLoy/config - ci