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

Add support for metadata in gluamapper.Option struct #3

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

Conversation

dnaeon
Copy link

@dnaeon dnaeon commented Jun 18, 2016

Adding support for metadata allows for inspecting the result of decoding and is useful in situations where we need to verify a list of required fields or unused ones.

A better approach would be to simply embed mapstructure.DecoderConfig in gluamapper.Option, but doing that would introduce a breaking API change, so with this commit I'm simply adding mapstructure.Metadata to gluamapper.Option struct for now. In future commits we should probably consider simply embedding DecoderConfig into Option struct.

@yuin
Copy link
Owner

yuin commented Jun 22, 2016

Thanks for you PR, and sorry for my late reply.(My job has gotten a little busy)

I think that it would be better to hide backend library APIs from gluermapper APIs.

Adding something like the following code to gluamapper.go

type Metadata struct {
    Keys []string
    Unused []string
}
    metadata := &mapstructure.Metadata{}
    metadata.Keys = opt.Metadata.Keys
    metadata.Unused = opt.Metadata.Unused 
    config := &mapstructure.DecoderConfig{
        WeaklyTypedInput: true,
        Result:           st,
        TagName:          opt.TagName,
        ErrorUnused:      opt.ErrorUnused,
        Metadata:         metadata,
    }

Are you in favor of this plan?

@dnaeon
Copy link
Author

dnaeon commented Jun 22, 2016

Sounds good. Do you want me to update the PR or you will do it instead?

@yuin
Copy link
Owner

yuin commented Jun 22, 2016

I would appreciate it if you could update the PR.

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.

2 participants