Golang example config by @barluscuda.
This project shows a simple way to load application configuration in Go using:
.envsupport viagithub.com/joho/godotenv- typed config structs
- generic environment value loading with fallbacks
main.goloads.env, builds the config, and prints the resultconfig/defines env keys, config types, and the config loaderpkg/envloader/provides a generic helper for reading environment variables
The app uses these variables:
EXAM_APP_SERVER_DEBUGEXAM_APP_SERVER_PORT
Example .env:
EXAM_APP_SERVER_DEBUG=true
EXAM_APP_SERVER_PORT=3250go run .If .env is missing, the app falls back to system environment variables and default values.
You can also run the app with:
make rungo test ./...Or:
make testThe test suite covers:
- typed environment parsing for
string,int,bool, andtime.Duration - fallback behavior when environment variables are missing or invalid
- config loading from
EXAM_APP_SERVER_DEBUGandEXAM_APP_SERVER_PORT
EXAM_APP_SERVER_DEBUG=falseEXAM_APP_SERVER_PORT=3250
config result: {{true 3250}}
See LICENSE.