Repository navigation
Conversation
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.
Overview
DecodeHook's doc comment states the wrong default decode hook. One-line doc fix.What problem does it solve?
viper.go:58-64documents the default as:but
defaultDecoderConfig— the function that actually establishes the default, atviper.go:1003-1007— uses Viper's own weak-slice hook, and the mapstructure one is explicitly commented out right above it:stringToWeakSliceHookFuncis described atviper.go:1026-1028: mapstructure v2.0.0'sStringToSliceHookFuncchecks that the target is a string slice, and this helper removes that check (viper.go:1035only testst.Kind() != reflect.Slice), so comma-splitting also reaches non-string slice fields, whose elements are then converted byWeaklyTypedInput. That is a real behavioural difference, not a naming nit — and this text is what shows up on pkg.go.dev forDecodeHook.Change
Point the documented example at the hook that is actually used:
The other three mentions of
StringToSliceHookFuncin the repo are left alone because they are correct in place:viper.go:1005is the commented-out line being replaced,viper.go:1026is the comment explaining why it was replaced, andviper_test.go:900,938pass the strict hook explicitly to test the override path.Tests
Comment-only, so no test change is needed and no behaviour moves. I did not run
go build/go test— the command layer in this session refused all build and test invocations, so I am stating that rather than implying CI ran locally. The change is inside a//doc comment abovefunc DecodeHook, which cannot affect compilation;gofmt-relevant whitespace was preserved exactly (the tab-indented//\tblock is untouched apart from the identifier).Related issues
None. Checked the open PR list before starting: #2143 ("Export DefaultDecodeHook for composition") touches this same default in a different way — it extracts
defaultDecoderConfig's chain into an exportedDefaultDecodeHook()and does not edit lines 58-64 — so the two do not overlap textually, and this correction is worth landing either way. If #2143 merges first, the doc here should probably be reworded to nameDefaultDecodeHook()instead of the inlined chain.Note: this PR was prepared and submitted by an autonomous agent on behalf of
ump45nose(Viper has no AI-disclosure rule, but the authorship seems worth stating plainly for a doc change).