godotenv

A Go port of Ruby's dotenv that loads environment variables from .env files into your process, with zero third-party dependencies.

Library
Go
vv1.5.1
10,667 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
50 /100 Fair
Development Activity 20
Maintenance 20
Community 60
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
73 /100 Good
Architecture 72
Code Quality 85
Innovation 88
Learning Curve 45

godotenv is a small, dependency-free Go library that ports Ruby’s dotenv to the Go ecosystem, reading key-value pairs from a .env file and loading them into the process environment so twelve-factor apps can keep configuration and secrets out of source control. It exposes both a mutating API (Load, Overload) for wiring env vars into os.Getenv and a pure API (Read, Parse, Unmarshal) for callers who want a plain map[string]string instead, plus Write/Marshal for serializing a map back to .env format.

Beyond the library, the module ships an autoload subpackage for zero-code side-effect loading and a standalone godotenv CLI (cmd/godotenv) that runs another command with an env file preloaded. The parser supports comments, quoted values, variable expansion (${VAR}), export prefixes, and YAML-style key: value syntax, and the project has explicitly declared itself feature-complete, focusing further contributions on compatibility fixes and bug fixes rather than new functionality.

What You Get

  • A one-line godotenv.Load() call that reads .env from the working directory into os.Getenv
  • Non-destructive Load/Read and destructive Overload variants for controlling whether existing env vars are preserved or replaced
  • Pure functions (Parse, Unmarshal, UnmarshalBytes) that return a map[string]string instead of mutating global state, for callers who want isolation
  • Write/Marshal helpers to serialize a map[string]string back into a correctly quoted and escaped .env file
  • An autoload subpackage for import-only side-effect loading (import _ "github.com/joho/godotenv/autoload")
  • A standalone godotenv CLI binary that runs an arbitrary command with env vars preloaded from one or more files

Common Use Cases

  • Loading local development secrets (API keys, DB URLs) from a .env file that’s excluded from version control
  • Bootstrapping environment-specific configuration by chaining .env, .env.{ENV}, and .env.local loads in a defined precedence order
  • Running a process with an injected environment via the CLI without modifying shell profile or CI job configuration
  • Reading env vars into an isolated map (via Read/Parse) for testing or for merging with other config sources instead of mutating the real process environment

Under The Hood

Architecture

The module is a flat, single-purpose Go package: godotenv.go exposes the public API (Load, Overload, Read, Parse, Unmarshal, Write, Exec), while parser.go isolates the actual parsing logic (parseBytes, getStatementStart, locateKeyName, extractVarValue) behind that surface. There’s no dependency injection or interface abstraction — it’s straightforward procedural Go built around a byte-slice “cutset” technique, where each parse step consumes a prefix of the remaining bytes and returns what’s left, avoiding per-line allocations. Two satellite packages extend the core without touching it: autoload wraps Load() in an init() for side-effect-only imports, and cmd/godotenv is a thin CLI wrapping Exec(). Because every public entry point (Parse, Unmarshal, UnmarshalBytes, file loading) ultimately funnels through parseBytes, that function is the single point where a change would ripple across the entire public API.

Tech Stack

Zero third-party runtime dependencies — the entire library is built on the Go standard library (bytes, os, os/exec, regexp, sort, strings, unicode, errors), targeting go 1.13 per go.mod. The CLI uses the stdlib flag package rather than a third-party CLI framework. Tooling is plain go build/go install; CI runs standard go test/vet plus a CodeQL security scan, and Dependabot keeps GitHub Actions versions current. Distribution is purely as an importable module (and an installable CLI via go install), with no runtime services or external integrations.

Code Quality

The test file is substantially larger than the combined source it covers, and is driven by dedicated fixture .env files exercising comments, quoting, exports, variable substitution, hyphenated keys, and deliberately invalid syntax. Parse failures return typed sentinel errors (ErrZeroLengthString, ErrUnexpectedChar, ErrUnterminatedQuote) wrapped with fmt.Errorf("%w ...") rather than being swallowed or panicking. Naming follows idiomatic Go conventions throughout (exported PascalCase API, unexported camelCase internals), and CI plus CodeQL static analysis run on every change. No dedicated linter config file was found, but the codebase is small enough that this has limited practical impact.

API Design The public surface favors minimal boilerplate: godotenv.Load() with no arguments loads .env from the current directory in one line, matching the ergonomics of Ruby’s and Node’s dotenv equivalents. Verb naming is consistent and orthogonal rather than one overloaded function with flags — Load/Overload mutate process env, Read/Parse/Unmarshal/UnmarshalBytes return a plain map without side effects, and Write/Marshal invert the process for serialization. Every exported symbol carries a godoc comment with a runnable usage snippet, and the autoload subpackage reduces the common case to a single blank import with zero application code required.

Used by 27 apps in this directory

Go
51%
MIT

Fathom Lite

Analytics

8,019

A simple, self-hosted website analytics tool built with Go and Preact that lets you understand your traffic without handing data to third parties.

View details
47
Repo Health
67
Technical
67
Dependency
Built with
Go 51%
JavaScript 31%
CSS 15%
Updated 7 months ago
Go
66%
AGPL 3.0

Fider

Customer Support · Product Management

4,586

Open-source feedback portal where customers submit, vote on, and track feature requests so product teams build what actually matters.

View details
88
Repo Health
85
Technical
65
Dependency
Built with
Go 66%
TypeScript 28%
Updated 1 weeks ago
Go
70%
MIT

Gotify

Developer Tools · Monitoring

16,111

A lightweight, self-hosted push notification server that sends and receives messages in real time over WebSocket, with a sleek web UI and a native Go plugin system.

View details
90
Repo Health
74
Technical
70
Dependency
Built with
Go 70%
TypeScript 29%
Updated 1 weeks ago
Go
62%
Apache 2.0

Harness Open Source

Code Editors · Developer Tools · Devops

38,684

A unified open source DevOps platform combining Git hosting, CI/CD pipelines, cloud development environments, and artifact registries in a single self-hosted system.

View details
90
Repo Health
79
Technical
64
Dependency
Built with
Go 62%
TypeScript 33%
Updated 1 weeks ago
PHP
60%
AGPL 3.0

Hyvor Relay

AI Development · Devops · Monitoring

918

Self-hosted, open-source email API that automates DNS, manages SMTP delivery, and provides deep observability — replacing SES, Mailgun, and SendGrid with infrastructure you fully own.

View details
69
Repo Health
79
Technical
71
Dependency
Built with
PHP 60%
Svelte 22%
Go 16%
Updated 1 weeks ago
Go
97%
Apache 2.0

infracost

Developer Tools · Devops

12,585

Infracost shows cloud cost estimates for Terraform, CloudFormation, and AWS CDK before you deploy — in your terminal, editor, AI coding agent, and pull requests.

View details
83
Repo Health
78
Technical
68
Dependency
Built with
Go 97%
Updated 1 weeks ago
TypeScript
44%
MIT

Kuku

Note Taking

230

A local-first, open-source Markdown knowledge workspace for macOS — plain files, personal wiki and Second Brain workflows, AI-assisted diffs, and encrypted sync, built as an Obsidian alternative.

View details
77
Repo Health
67
Technical
67
Dependency
Built with
TypeScript 44%
Rust 41%
Updated 1 weeks ago
TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,055

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
68
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 2 months ago
Go
53%
MIT

memos

Note Taking

64,031

Open-source, self-hosted note-taking built for quick capture — Markdown-native, lightweight, and fully yours.

View details
91
Repo Health
78
Technical
65
Dependency
Built with
Go 53%
TypeScript 46%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers