Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(decoder): support multiple tag names in order #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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

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
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.

1 participant