Skip to content

Conversation

@DarkiT
Copy link

@DarkiT DarkiT commented Jan 21, 2025

Add support for comma-separated tag names in DecoderConfig.TagName. The decoder will try each tag name in order and use the first valid tag value found.

Example:
config := &DecoderConfig{
TagName: "mapstructure,yaml,json",
Result: &Config{},
}

This allows more flexible struct field mapping by supporting multiple tag formats while maintaining backwards compatibility with single tag name usage.

The decoder will:

  1. Try each tag name in the specified order
  2. Use the first valid tag value found
  3. Fall back to field name if no tag found
  4. Skip field if IgnoreUntaggedFields is true and no tag found

Changes:

  • Update DecoderConfig.TagName comment to document multiple tag support
  • Modify decodeStructFromMap to handle comma-separated tag names
  • Keep backwards compatibility with single tag name usage

@derekperkins
Copy link

@sagikazarmark any chance you could take a look at this?

@sagikazarmark
Copy link
Member

I've put this on my list, I'll try to get this reviewed shortly.

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
@sagikazarmark sagikazarmark merged commit dee4661 into go-viper:main Jan 12, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants