env

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package env provides functionality for loading environment variables.

The variables are primarily sourced from optional .env files located within the project directory. These .env files offer a convenient method for setting environment variables for both development and production.

The package features an AutoLoad function. AutoLoad is designed to automatically load environment variables from a default .env file.

Additionally, AutoLoad checks for the existence of .env.<ENV>.local and .env.local files, loading variables from them if they are found. This functionality allows for environment-specific variables to be set, thereby enhancing the flexibility of the environment configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoLoad

func AutoLoad(defaultEnvContent string) error

AutoLoad loads the default .env file and the .env.local file if it exists. The default .env file is expected to be embedded in the binary, and provided as the defaultEnvContent argument.

It also loads the .env.<ENV>.local file if the ENV environment variable is set. If the ENV environment variable is not set, it defaults to "dev".

Types

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader loads environment variables from a file.

func NewLoader

func NewLoader() *Loader

NewLoader creates a new Loader.

func (*Loader) Apply

func (l *Loader) Apply(content string) error

Apply loads the environment variables from the given content.

func (*Loader) LoadOptional

func (l *Loader) LoadOptional(file string) error

LoadOptional loads the environment variables from the given file. It ignores the file if it does not exist.

Jump to

Keyboard shortcuts

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