godotenv
A Go port of Ruby's dotenv that loads environment variables from .env files into your process, with zero third-party dependencies.
Repository Health
Technical Analysis
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.envfrom the working directory intoos.Getenv - Non-destructive
Load/Readand destructiveOverloadvariants for controlling whether existing env vars are preserved or replaced - Pure functions (
Parse,Unmarshal,UnmarshalBytes) that return amap[string]stringinstead of mutating global state, for callers who want isolation Write/Marshalhelpers to serialize amap[string]stringback into a correctly quoted and escaped.envfile- An
autoloadsubpackage for import-only side-effect loading (import _ "github.com/joho/godotenv/autoload") - A standalone
godotenvCLI 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
.envfile that’s excluded from version control - Bootstrapping environment-specific configuration by chaining
.env,.env.{ENV}, and.env.localloads 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
MentraOS
AI Development · Developer Tools
The open source operating system and SDK that lets developers build one app and run it across smart glasses from Even Realities, Vuzix, Mentra Live, and more.
OpenStatus
Devops · Monitoring
Open-source status pages and uptime monitoring with global synthetic checks, monitoring-as-code, and AI agent integration via MCP.
OpenReplay
Analytics
Self-hosted session replay and product analytics suite that lets you see exactly what users do on your web app — without sending data to third parties.
PeerDB
Data Engineering · Databases
Postgres-native ETL that streams change data capture in real time to Snowflake, BigQuery, ClickHouse, S3, and Kafka — up to 10x faster than general-purpose pipelines, managed through a familiar Postgres SQL interface.
Portainer
Devops
A lightweight, open-source web UI that puts Docker, Kubernetes, and Podman management within reach of any team—no CLI expertise required.
PrivateCaptcha
Authentication · Security
Privacy-first, self-hostable Proof-of-Work CAPTCHA for GDPR-compliant bot protection.
Rill
Analytics · Data Engineering
The fastest BI tool for humans and agents — define metrics, models, and dashboards as code and query them instantly on ClickHouse or DuckDB.
Stormkit
Devops · Hosting Control Panel
Self-hostable platform for deploying and hosting modern web apps with automated CI/CD, custom domains, and a built-in serverless runtime — a true open-source alternative to Vercel and Netlify.
Trieve
AI Development · Developer Tools · Search
All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.