Skip to content

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 Loader is 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
NeedEntry point
Get started in 5 minutesQuick Start
Store passwords and keys securelySecurity Overview → SecureValue
Prevent sensitive data from being swapped to diskMemory Locking
Safely handle sensitive data in logsData Masking
Map environment variables to a structStruct Mapping
Load JSON/YAML config filesMulti-format Config
Configure variable references and reuseVariable Expansion
Serialize/export configurationSerialization
Record security audit logsAudit Logging
Handle and match errorsError Handling
Share a loader across goroutines and manage its lifecycleConcurrency & Lifecycle
Write unit testsTesting
Extend with custom file formatsCustom Parser
Review performance data and tuningPerformance
Run the official examplesExamples
Security checks before going liveProduction Checklist
See common code snippetsCheat Sheet
Find answers to common questionsFAQ

Start Here ​