gotenv

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

README

gotenv

Build Status Go Reference

Parse dotenv, safe & fast, in Go using Ragel.

Documentation

Overview

Package gotenv implements reading dotenv files and setting env variables based on their content.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(filenames ...string) error

Load given dotenv files.

Load combines Read and Setenv. As a result, the env variables within the current process are set according to the definitions in given files; see Read for the notes on syntax.

func Setenv added in v0.4.0

func Setenv(env []EnvVar) error

Setenv sets the env variables within the current process according to the given `env` argument, most likely produced by Read.

Important: if the variable existed in the process env prior to this call, it will *not* be set.

Types

type EnvVar added in v0.4.0

type EnvVar struct {
	Key, Val string
}

func Read added in v0.4.0

func Read(filenames ...string) (env []EnvVar, _ error)

Read reads dotenv files.

Files should contain variable definitions in a form `KEY=VALUE`. Whitespaces at the beginning of the line and around equal sign `=` are allowed and ignored. If the value is surrounded by the single `'` or double `"` quotes, it will be passed to the env unquoted. No value after equal sign means that the variable will be reset to empty. Hash sign `#` acts as a comment, ignoring everything until the end of line, unless it's within quotes. If there are multiple definitions for the same KEY, in a single file or spanning multiple files, the last definition wins.

If there is no given file, `.env` is assumed.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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