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 'required' tag value #167

Closed
wants to merge 1 commit into from

Conversation

bonifaido
Copy link

Implementation for checking that required fields got filled in map -> struct decoding direction.

A basic test has been added as well.

type Required struct {
	RequiredBar string `mapstructure:"bar,required"`
	Value       string `mapstructure:"foo"`
}

Fixes: #7

@janderland
Copy link

Would be nice if this could be set globally as well, for all fields.

@philippfrank
Copy link

@bonifaido I was looking exactly for this. What's the status?

@bonifaido
Copy link
Author

I need to rebase on master now I guess, since this is almost 1 year old, after that I'm waiting on a review/merge 🙂

@bonifaido bonifaido force-pushed the required branch 2 times, most recently from 39194a0 to 1a6dfa8 Compare May 6, 2020 09:19
@bonifaido
Copy link
Author

Rebased it on latest master.

@philippfrank
Copy link

@mitchellh Are there any plans to merge/review this? It's a really helpful addition!

@dz0gchen
Copy link

need merge

@wang502
Copy link

wang502 commented May 19, 2020

this is feature is really helpful. can we give this a review? thanks :) @mitchellh

@montaro
Copy link

montaro commented Jun 14, 2020

Please merge

@wangshuai14
Copy link

It seems not working. Are there errors in my code?
image

@bonifaido
Copy link
Author

Are you using my fork@branch @wangshuai14 ?

@wangshuai14
Copy link

Are you using my fork@branch @wangshuai14 ?

Got it! thanks

@bonifaido
Copy link
Author

bonifaido commented Sep 17, 2020

Just rebased on the latest master to see its working.

@Etran-H
Copy link

Etran-H commented Jan 18, 2022

@mitchellh
can comment on this?

@cmatthias
Copy link

If it's helpful to anyone, I forked mapstructure and merged this PR as well as #225 into my fork. Feel free to use.

https://github.com/cmatthias/mapstructure

@mitchellh
Copy link
Owner

Hello all. Its been 3 years, and I've sat on this. I've integrated mapstructure into a dozen or more projects by this point. I've certainly run into this issue before. I believe that its better to use a full featured struct validation library rather than support this one feature in mapstructure. I've always reached for something like ozzo-validation or validator and felt that was just the better approach. I'm sorry, but I want to keep this library as focused on the decoding problem rather than data validation (beyond simple type matching -- necessary for decoding).

@mitchellh
Copy link
Owner

Actually #225 is a great approach to this that I think balances the line between enabling this sort of functionality but not stepping into what in my opinion is validation territory in the same way. I'll merge that.

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.

Add config to error if field is NOT set
10 participants