caarlos0 / env

A simple, zero-dependencies library to parse environment variables into structs

Home Page:https://pkg.go.dev/github.com/caarlos0/env/v11

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.env file support?

lordvidex opened this issue · comments

With this package, is it possible to load .env files?

No AFAIK but you can use it with godotenv. Something like:

package config

import (
	"github.com/caarlos0/env/v8"
	_ "github.com/joho/godotenv/autoload"
)

type Config struct {
	DatabaseUrl string `env:"DATABASE_URL"`
	Host        string `env:"HOST"`
	Port        string `env:"PORT"`
}

func New() *Config {
	var cfg Config

	env.Parse(&cfg)

	return &cfg
}