-
Notifications
You must be signed in to change notification settings - Fork 32
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
Implement unmarchaling #2
Comments
Can you explain what benefit that would bring over standard Golang JSON Unmarshal? |
Let's pick this case: Using a PATCH update the fields that are passed (and that the user is authorized). Trying to solve this, I did 2 different attempts: Double json unmarshalingDecode the POST data to Object with json/unmarshal, Filter the object with sheriff/marshal, marshal the map with json/marshal, unmarshal again with json/unmarshal. mapstructureThe other method I came out with is: I think this scenario is pretty common and I think that an unmarshaling function could help here :) |
Hm.. I don't quite get why you do it that complicated?
You have a struct representing this:
Now you want to PATCH that Post in a Request:
Why can't you just use normal |
The problem is that in that way I can not protect - for instance - the CreatedBy field, which I want to have it in "read-only mode". If I just |
But you anyway need to check what's in the update and potentially reply with a bad request in case the request contains things you don't want to be updated. |
Yes I do, but I was trying to create a more generic code, adding some "publicupdate", "privateupdate", etc groups to semplify the code in the function because having 30+ fields and many different access levels, the code becomes very clunky otherwise |
But what would you want the lib to do when more data is passed than "allowed"? IMO sheriff is not a validation library, which is probably what you rather want (and maybe exists?).. no? |
Yeah, I ended up implementing a couple of methods that I can share based on sheriff and reflection to actually do validation as well :). Thanks for the great library! |
ok, let me know in case you published it somewhere :) |
I think it would be very useful to also implement unmarshaling functions to be able to secure also writes for post/put/patch.
The text was updated successfully, but these errors were encountered: