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,604stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
54/100Fair
Development Activity36
Maintenance20
Community60
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture72
Code Quality85
Innovation88
Learning Curve45

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 25 apps in this directory

Go
72%
GPL 3.0

1Panel

Devops · Hosting Control Panel · Monitoring

36,721

The only open-source VPS control panel with native AI agent runtime — deploy websites, Docker stacks, and local LLMs from one web interface.

View details
90
Repo Health
76
Technical
68
Dependency
Built with
Go72%
Vue28%
Updated 2 days ago
Go
60%
Apache 2.0

Apache Answer

Community

15,658

Open-source Q&A platform for communities, help centers, and knowledge bases with AI assistant and plugin extensibility

View details
84
Repo Health
78
Technical
68
Dependency
Built with
Go60%
TypeScript36%
Updated 2 days ago
Go
55%
Apache 2.0

Authgear

Authentication

2,014

Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.

View details
88
Repo Health
81
Technical
69
Dependency
Built with
Go55%
HTML25%
TypeScript17%
Updated 4 days ago
Go
75%
AGPL 3.0

Coder

Devops · Developer Tools · Code Editors

14,299

Self-hosted cloud development environments and AI coding agents — defined in Terraform, connected via WireGuard, automatically shut down when idle.

View details
93
Repo Health
90
Technical
69
Dependency
Built with
Go75%
TypeScript23%
Updated today
Go
98%
Other

Crush

Developer Tools · AI Code Assistants · AI Assistants

27,798

Your terminal coding companion — wire up any LLM with LSP intelligence, MCP extensibility, and a skills system that learns your workflow.

View details
87
Repo Health
86
Technical
69
Dependency
Built with
Go98%
Updated today
Shell
48%
MIT

Dokku

Devops · Hosting Control Panel

32,114

The smallest PaaS implementation you've ever seen — deploy apps via git push using Docker and Heroku buildpacks on your own server.

View details
93
Repo Health
85
Technical
71
Dependency
Built with
Shell48%
Go48%
Updated today
TypeScript
98%
Other

Dokploy

Devops · Hosting Control Panel · Security

36,965

Self-hosted PaaS that deploys apps and databases on your own VPS using Docker, Traefik, and multi-build-system orchestration

View details
88
Repo Health
76
Technical
65
Dependency
Built with
TypeScript98%
Updated 2 days ago
Go
43%
Apache 2.0

e2a

AI Agents · Automation

184

Give your AI agents a real, authenticated email address — with SPF/DKIM-verified inbound, HMAC-signed delivery, WebSocket fan-out, and human-in-the-loop approval built in.

View details
78
Repo Health
80
Technical
74
Dependency
Built with
Go43%
TypeScript28%
Python14%
Updated today
Go
51%
MIT

Fathom Lite

Analytics

8,013

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
48
Repo Health
67
Technical
68
Dependency
Built with
Go51%
JavaScript31%
CSS15%
Updated 5 months 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

Search