Categorygithub.com/go-zoox/dotenv
modulepackage
1.3.0
Repository: https://github.com/go-zoox/dotenv.git
Documentation: pkg.go.dev

# README

DotEnv

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

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"))

Inspired by

# Functions

Get gets the value of the given key from system environment.
Load loads the .env file into the environment.
LoadToEnv loads the .env file into environment.

# Variables

Version is the current version of the package.

# Structs

EnvDataSource is a data source that loads data from the environment.