refactor: drop viper #761 BindEnv workaround#412
Merged
Conversation
viper v1.21.0 resolves env vars via AutomaticEnv() during Unmarshal as long as a SetDefault exists for the key, making the explicit BindEnv loop redundant. Add empty defaults for the six previously-unbound keys (secret + customize.* overrides) so they continue to resolve. The removed loop also bound env names without the OCAP_ prefix as a side effect; update the affected test to use the documented OCAP_ prefix.
Merging this branch will increase overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces several new default configuration settings for the server, including a secret key and various customization options such as website URL, logo, and header titles. Additionally, it removes a manual environment variable binding workaround in internal/server/setting.go and updates the test suite to use the OCAP_ prefix for environment variables. I have no feedback to provide.
smitt14ua
pushed a commit
to smitt14ua/OCAP2-web
that referenced
this pull request
May 1, 2026
viper v1.21.0 resolves env vars via AutomaticEnv() during Unmarshal as long as a SetDefault exists for the key, making the explicit BindEnv loop redundant. Add empty defaults for the six previously-unbound keys (secret + customize.* overrides) so they continue to resolve. The removed loop also bound env names without the OCAP_ prefix as a side effect; update the affected test to use the documented OCAP_ prefix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
go.mod) resolves env vars viaAutomaticEnv()duringUnmarshalas long as the key has aSetDefault. The explicitBindEnvloop is no longer needed.envKeysslice + loop, add empty defaults for the six previously-unbound keys (secret,customize.websiteURL,customize.websiteLogo,customize.disableKillCount,customize.headerTitle,customize.headerSubtitle) so they continue to resolve from env.OCAP_prefix (e.g.CONVERSION_ENABLED). Only the documentedOCAP_-prefixed names are accepted now, matchingSetEnvPrefix("ocap")andCLAUDE.md. The affectednested env vars with underscoretest was updated accordingly.Test plan
go test ./internal/server/...passesgo build ./...cleanOCAP_SECRET,OCAP_CUSTOMIZE_WEBSITEURL,OCAP_CONVERSION_ENABLED, etc. still take effect at runtime