env
env is a Go library for managing environment variables. It loads .env, JSON, and YAML files, converts values to Go types, protects sensitive values in memory, and records audit events.
Core Features
- Multi-format loading -
.env, JSON, and YAML, picked by file extension - Type safety - typed getters with conversion and validation
- Concurrency safety - one
Loaderis safe to share across goroutines - Secure storage - memory locking and zeroing for sensitive values
- Audit logging - records load, set, and delete operations
- Variable expansion -
${VAR}and${VAR:-default}references - Struct mapping - tag-driven binding into Go structs
Navigate by Use Case
| Need | Entry point |
|---|---|
| Get started in 5 minutes | Quick Start |
| Store passwords and keys securely | Security Overview → SecureValue |
| Prevent sensitive data from being swapped to disk | Memory Locking |
| Safely handle sensitive data in logs | Data Masking |
| Map environment variables to a struct | Struct Mapping |
| Load JSON/YAML config files | Multi-format Config |
| Configure variable references and reuse | Variable Expansion |
| Serialize/export configuration | Serialization |
| Record security audit logs | Audit Logging |
| Handle and match errors | Error Handling |
| Share a loader across goroutines and manage its lifecycle | Concurrency & Lifecycle |
| Write unit tests | Testing |
| Extend with custom file formats | Custom Parser |
| Review performance data and tuning | Performance |
| Run the official examples | Examples |
| Security checks before going live | Production Checklist |
| See common code snippets | Cheat Sheet |
| Find answers to common questions | FAQ |
Start Here
- Quick Start - install, load a
.envfile, read typed values - Cheat Sheet - one-page snippet reference
- Package Functions - full function reference
- Loader - instance methods and lifecycle
- SecureValue - secure value handling
- Security Overview - security architecture and defaults