gotenv

package module
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2025 License: MIT Imports: 6 Imported by: 2

Documentation

Overview

gotenv is a general-purpose package to load environment variables from files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadEnv

func LoadEnv(opts ...LoadOptions) (map[string]string, error)

LoadEnv loads environment variables from a given file name specified in the given optional parameter opts. Default values are given by DefaultLoadOptions.

This function returns a map of the environment variables that were added by the environment file, and an error if one occurred. Environment variables can also be accessed normally using os.Getenv.

func LoadEnvFromFS

func LoadEnvFromFS(fsys fs.FS, opts ...LoadOptions) (map[string]string, error)

LoadEnvFromFS loads environment variables from a given file name specified in the given optional parameter opts, using the given file system fsys. Default values for opts are given by DefaultLoadOptions.

This function returns a map of the environment variables that were added by the environment file, and an error if one occurred. Environment variables can also be accessed normally using os.Getenv.

func LoadEnvFromReader

func LoadEnvFromReader(reader io.Reader, opts ...LoadEnvFromReaderOptions) (map[string]string, error)

LoadEnvFromReader loads environment variables from a given io.Reader. Default values for opts are given by DefaultLoadEnvFromReaderOptions.

This function returns a map of the environment variables that were added by the environment file, and an error if one occurred. Environment variables can also be accessed normally using os.Getenv.

Types

type LoadEnvFromReaderOptions

type LoadEnvFromReaderOptions struct {
	OverrideExistingVars bool
}

LoadEnvFromReaderOptions is a struct that contains options for the LoadEnvFromReader function.

func DefaultLoadEnvFromReaderOptions

func DefaultLoadEnvFromReaderOptions() LoadEnvFromReaderOptions

DefaultLoadEnvFromReaderOptions returns the default options for the LoadEnvFromReader function. The default options are:

OverrideExistingVars: true

type LoadOptions

type LoadOptions struct {
	OverrideExistingVars bool
	FileName             string
}

LoadOptions is a struct that contains options for the LoadEnv and LoadEnvFromFS functions.

func DefaultLoadOptions

func DefaultLoadOptions() LoadOptions

DefaultLoadOptions returns the default options for the LoadEnv and LoadEnvFromFS functions. The default options are:

OverrideExistingVars: true
FileName: ".env"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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