feat(config): create configuration system #129
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
thwap/thwap-pagesd!129
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/configuration-system"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Implement the configuration system for
thwap-pagesd:Configstruct with nested sections:Listener,Forgejo,Kubernetes,Webhook,Loggingconfig.Load(path)resolves in precedence order: defaults → config file → environment variables--configpath or automatic lookup in cwd,$HOME/.config/thwap-pagesd, and/etc/thwap-pagesdTHWAP_PAGESD_prefix and.→_mapping (e.g.THWAP_PAGESD_FORGEJO_TOKEN):8080, k8s namespacethwap-pagesd, log levelinfocmd/thwap-pagesd/main.gowith a--configflagtestdata/Why
Phase 1 task #17 — the configuration layer that all later phases (Forgejo, Kubernetes, HTTP API, webhook) consume.
Testing
go mod tidygo vet ./...go test -race ./...— 6 new config tests passgo build ./cmd/thwap-pagesdgofmt -l ./cmd ./internalcleangolangci-lint run— 0 issuesBreaking Changes
None.
Notes
AutomaticEnvresolves env vars for keys without config file values.Closes #14
Closes #15
Closes #16
Closes #17
Review Summary
Verified locally on the PR head (
3b4e53a):go build,go vet,gofmt,golangci-lint runall pass, and all 6 config unit tests pass.Blocking Issue
internal/config/config.go:63— automatic config lookup cannot load TOML, despite the PR claiming "YAML and TOML, auto-detected by extension" for the auto-lookup path. The no-path branch callsv.SetConfigType("yaml"), which hardcodes the parse format. Viper'ssearchInPathiterates all supported extensions (TOML before YAML), so athwap-pagesd.tomlin cwd/$HOME/.config/thwap-pagesd//etc/thwap-pagesdis found — but thenReadInConfig→getConfigType()returns the forced"yaml"and the TOML is parsed as YAML, producing a hard startup error.Empirically reproduced: a
thwap-pagesd.tomlin the cwd fails withyaml: unmarshal errors: line 1: cannot unmarshal !!seq into map[string]interface {}.Fix: remove the
v.SetConfigType("yaml")line. Without it, viper derives the type from the found file's extension, exactly as it does in the explicit---configbranch (which is why TOML works there). One-line fix; all existing tests still pass (they only cover TOML via explicit path, so they don't catch this).Non-blocking Suggestions
TestLoadDefaults/TestLoadEnvWithoutFilecallLoad(""), which searches the real cwd,$HOME/.config/thwap-pagesd, and/etc/thwap-pagesd— a config file in any of those locations on a dev machine would make the tests flaky. Consider chdir-ing into at.TempDir()for the no-path cases.--configpointing at a missing file correctly errors (good), but the error messageread config: ...is generic — fine for now.The blocking item is a one-line fix.
Remove SetConfigType("yaml") from the auto-lookup branch so viper derives the parse format from the found file's extension. Without this, a thwap-pagesd.toml in the lookup paths was parsed as YAML and failed to load. Add a regression test for TOML auto-lookup and isolate no-path tests in a temp directory to avoid picking up config files from the dev machine.Review changes addressed in
26c081c:Blocking issue — removed
v.SetConfigType("yaml")from the auto-lookup branch ininternal/config/config.go. Viper now derives the parse format from the found file's extension, sothwap-pagesd.tomlin the lookup paths loads correctly (mirrors the explicit--configpath behavior).Non-blocking #1 — no-path tests (
TestLoadDefaults,TestLoadEnvWithoutFile) nowt.Chdirinto at.TempDir()so real config files on the dev machine can't cause flakiness.Regression test added —
TestLoadAutoLookupTOMLreproduces the reported scenario (TOML in cwd viaLoad("")) and passes.Verified:
go build,go vet,gofmt,golangci-lint runclean; all 7 config tests pass.Review Summary
Both issues from the previous review are resolved.
v.SetConfigType("yaml")removed from the auto-lookup branch (internal/config/config.go). Viper now derives the format from the found file's extension, sothwap-pagesd.tomlin cwd/$HOME/.config/thwap-pagesd//etc/thwap-pagesdloads correctly.TestLoadAutoLookupTOMLexercises exactly the previously-broken path (temp cwd + TOML fixture +Load("")) and passes.TestLoadDefaults/TestLoadEnvWithoutFilenow chdir into at.TempDir(), removing the external-config dependency.Verified locally on the PR head (
26c081c):go build,go vet,gofmt,golangci-lint runall clean; all 7 config tests pass with-race.No blocking issues. Approving.