ubgo is in early alpha: libraries and APIs may still change.

Skip to content
ubgo Alpha

dotenv

.env parser and editor that keeps comments, order and quoting, plus the dotenvctl CLI.

go get github.com/ubgo/dotenv
Language
Go
Go version
1.22
Core deps
0 direct
Latest tag
v0.1.3
License
Apache-2.0
Go modules
2

Code from the README

// Example_reading shows what each read accessor returns for a file with a
// duplicated key and a commented-out setting: duplicates resolve to the last
// occurrence, and disabled lines are invisible to every accessor.
func Example_reading() {
	f := dotenv.Parse("A=1\nB=2\nA=3\n# C=off\n")

	v, ok := f.Get("A")
	fmt.Println(v, ok)             // last occurrence wins
	fmt.Println(f.Has("C"))        // disabled lines are not active keys
	fmt.Println(f.Count("A"))      // how many active A lines exist
	fmt.Println(f.Keys())          // active keys, file order, deduplicated
	fmt.Println(len(f.Pairs()))    // active pairs, duplicates included
	fmt.Println(f.Map()["A"])      // effective view
	fmt.Println(len(f.Disabled())) // the commented-out setting is still known
	// Output:
	// 3 true
	// false
	// 2
	// [A B]
	// 3
	// 3
	// 1
}

From the dotenv README.

At a glance (from the README)

FamilySemanticsUse for
Set, SetAfter, SetBeforeupsert — guarantees one active entry; updates in place if the key existsediting
Append, InsertAfter, InsertBeforeliteral — places exactly what you pass, duplicates includedgenerating