Explores three main approaches for managing configuration settings in Go web applications: command-line flags (using the standard flag package), environment variables (with os.Getenv()), and configuration files (TOML, YAML, JSON). Demonstrates how to parse settings into a config struct, pass them to HTTP handlers through an application struct, and discusses the trade-offs of each approach. The author favors command-line flags for their built-in help text, type conversion, and clarity, while recommending configuration files for complex or numerous settings.

13m read timeFrom alexedwards.net
Post cover image
Table of contents
Example codeUsing command-line flagsUsing environment variablesUsing configuration filesPassing settings to where they are neededDiscussion

Sort: