dotenv

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dotenv parses and renders .env files.

Index

Constants

View Source
const (
	MaxBytes    = 16 * 1024 * 1024
	MaxEntries  = 4096
	MaxKeyBytes = 1024
)

Variables

View Source
var (
	ErrInvalid = errors.New("invalid dotenv")
)

Functions

func Format

func Format(secrets map[string]string) ([]byte, error)

Format renders sorted, double-quoted assignments that Parse reads back. It refuses secrets Parse would reject, so a written file can always be read again.

func Parse

func Parse(data []byte) (map[string]string, error)

Parse accepts assignments, optional export, comments, and single/double quoted values (including multiline values). Double quotes support \\, \" and escaped n/r/t/$; unquoted and single-quoted values remain literal. It never performs variable expansion, reads the environment, or executes code. Duplicate keys are rejected rather than silently overwriting a secret.

The text is UTF-8, or UTF-16 with a byte order mark: what Windows PowerShell 5.1 writes with > or Out-File.

func Text

func Text(data []byte) ([]byte, error)

Text returns a dotenv file's content as UTF-8: UTF-16 that starts with a byte order mark is converted, anything else is returned as it is. Malformed UTF-16 (an odd length or an unpaired surrogate) is ErrInvalid, so a secret is never stored with a replacement character in place of what was there.

Types

This section is empty.

Jump to

Keyboard shortcuts

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