Load every setting from one table in internal/config (closes #320)
check / check (push) Canceled after 0s

Config.settings lists each setting once: its key, its environment
variable and the function that loads it. Most rows load through field,
whose arguments give the type, the default and the check. db_url and
cache_max_bytes keep their own load functions. Loading, the unknown-key
and unknown-variable checks and the names in error messages all read
the table. allowlist_hosts now loads through parseHostList, as
referer_blocklist does. isKnownConfigKey, envVarNames, strictLoader,
validate, validateAllowlistHostsValue and getStringSlice are gone, with
the getStringSlice tests. The key constants move to the tests, their
only users. A new test checks that README.md and
configs/config.example.yml name the keys of the table.

Model: opus-5-5
This commit is contained in:
2026-10-26 20:49:38 +00:00
parent b73bbde46e
commit fdcf1a3c61
6 changed files with 507 additions and 673 deletions
+4 -3
View File
@@ -138,7 +138,8 @@ func TestPixaPortAbortsStartupPointingToPort(t *testing.T) {
// TestSettingVariablesAndConfigPathAreAccepted checks that every
// setting's variable and PIXA_CONFIG_PATH pass the check for unknown
// PIXA_ variables. TestEnvironmentSetsEveryKey pins the names in the list.
// PIXA_ variables. TestEnvironmentSetsEveryKey pins the names in the
// settings table.
func TestSettingVariablesAndConfigPathAreAccepted(t *testing.T) {
// A config file's env section loaded by another test can leave a
// PIXA_ variable set for the whole process, so every one is unset
@@ -159,8 +160,8 @@ func TestSettingVariablesAndConfigPathAreAccepted(t *testing.T) {
t.Setenv("PIXA_CONFIG_PATH", "/etc/pixa/config.yml")
for _, name := range envVarNames() {
t.Setenv(name, "")
for _, s := range new(Config).settings() {
t.Setenv(s.envVar, "")
}
err := validateKnownEnvVars()