dotenv

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 4 Imported by: 4

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.3.0"

Version is the current version of the package.

Functions

func Get

func Get(key string, defaultValue ...string) string

Get gets the value of the given key from system environment.

func Load

func Load(value interface{}, filenames ...string) error

Load loads the .env file into the environment.

func LoadToEnv added in v1.2.0

func LoadToEnv(filenames ...string) error

LoadToEnv loads the .env file into environment.

Types

type EnvDataSource added in v1.0.3

type EnvDataSource struct {
}

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

func (EnvDataSource) Get added in v1.0.3

func (EnvDataSource) Get(path, key string) any

Get returns the value of the given key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL