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

Need a way to "omitempty" #23

Closed
sheki opened this issue Feb 24, 2014 · 3 comments
Closed

Need a way to "omitempty" #23

sheki opened this issue Feb 24, 2014 · 3 comments

Comments

@sheki
Copy link

sheki commented Feb 24, 2014

Right now gorilla/schema does not have a way to omit non present values to empty.
For example :

type params struct {
   Username string `schema:"name"`
   Password string `scehma:"password,setempty"`
}

If the input map does not contain the key "password" it should set it to an empty value if the tag is provided.

We are running into an issue with this right now.

@kisielk
Copy link
Contributor

kisielk commented Feb 24, 2014

You could just set the field to an empty string prior to decoding.

The behaviour is pretty consistent with how other decoding modules such as encoding/json and encoding/xml work.

@sheki
Copy link
Author

sheki commented Feb 26, 2014

I agree that this behaves like json/encoding, but I still think having a an additional flag will be useful

@kisielk
Copy link
Contributor

kisielk commented Feb 26, 2014

Sorry, I don't agree, you can already achieve what you need without adding any additional flags to the package by just setting the field to the default value you want before decoding.

@kisielk kisielk closed this as completed Feb 26, 2014
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

No branches or pull requests

2 participants