...

Package gotenv

import "github.com/subosito/gotenv"
Overview
Index

Overview ▾

Package gotenv provides functionality to dynamically load the environment variables

func Apply

func Apply(r io.Reader) error

Apply is a function to load an io Reader then export the valid variables into environment variables if they do not exist.

func Load

func Load(filenames ...string) error

Load is a function to load a file or multiple files and then export the valid variables into environment variables if they do not exist. When it's called with no argument, it will load `.env` file on the current path and set the environment variables. Otherwise, it will loop over the filenames parameter and set the proper environment variables.

func Marshal

func Marshal(env Env) (string, error)

Marshal outputs the given environment as a env file. Variables will be sorted by name.

func Must

func Must(fn func(filenames ...string) error, filenames ...string)

Must is wrapper function that will panic when supplied function returns an error.

func OverApply

func OverApply(r io.Reader) error

OverApply is a function to load an io Reader then export and override the valid variables into environment variables.

func OverLoad

func OverLoad(filenames ...string) error

OverLoad is a function to load a file or multiple files and then export and override the valid variables into environment variables.

func Write

func Write(env Env, filename string) error

Write serializes the given environment and writes it to a file

type Env

Env holds key/value pair of valid environment variable

type Env map[string]string

func Parse

func Parse(r io.Reader) Env

Parse is a function to parse line by line any io.Reader supplied and returns the valid Env key/value pair of valid variables. It expands the value of a variable from the environment variable but does not set the value to the environment itself. This function is skipping any invalid lines and only processing the valid one.

func Read

func Read(filename string) (Env, error)

Read is a function to parse a file line by line and returns the valid Env key/value pair of valid variables. It expands the value of a variable from the environment variable but does not set the value to the environment itself. This function is skipping any invalid lines and only processing the valid one.

func StrictParse

func StrictParse(r io.Reader) (Env, error)

StrictParse is a function to parse line by line any io.Reader supplied and returns the valid Env key/value pair of valid variables. It expands the value of a variable from the environment variable but does not set the value to the environment itself. This function is returning an error if there are any invalid lines.

func Unmarshal

func Unmarshal(str string) (Env, error)

Unmarshal reads a string line by line and returns the valid Env key/value pair of valid variables. It expands the value of a variable from the environment variable but does not set the value to the environment itself. This function is returning an error if there are any invalid lines.