Skip to content

barluscuda/go-example-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang Example Config

Golang example config by @barluscuda.

About

This project shows a simple way to load application configuration in Go using:

  • .env support via github.com/joho/godotenv
  • typed config structs
  • generic environment value loading with fallbacks

Project Structure

  • main.go loads .env, builds the config, and prints the result
  • config/ defines env keys, config types, and the config loader
  • pkg/envloader/ provides a generic helper for reading environment variables

Environment Variables

The app uses these variables:

  • EXAM_APP_SERVER_DEBUG
  • EXAM_APP_SERVER_PORT

Example .env:

EXAM_APP_SERVER_DEBUG=true
EXAM_APP_SERVER_PORT=3250

Run

go run .

If .env is missing, the app falls back to system environment variables and default values.

You can also run the app with:

make run

Test

go test ./...

Or:

make test

The test suite covers:

  • typed environment parsing for string, int, bool, and time.Duration
  • fallback behavior when environment variables are missing or invalid
  • config loading from EXAM_APP_SERVER_DEBUG and EXAM_APP_SERVER_PORT

Default Values

  • EXAM_APP_SERVER_DEBUG=false
  • EXAM_APP_SERVER_PORT=3250

Example Output

config result: {{true 3250}}

License

See LICENSE.

About

Golang example config by @barluscuda

Topics

Resources

License

Stars

Watchers

Forks

Contributors